Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question jquery prependTo() doesn't work ?

    hi, I don't really know what's going on, am just starting to learn jquery.
    in my practice code, the "back to top" link doesn't appear.

    here's my html code
    Code:
    <div class="chapter">
    <p class="square">Our Professional Men and Gentlemen are
    Squares (to which class I myself belong) and Five-Sided
    Figures or <a
    href="http://en.wikipedia.org/wiki/Pentagon">Pentagons
    </a>.
    </p>
    <p class="nobility hexagon">Next above these come the
    Nobility, of whom there are several degrees, beginning at
    Six-Sided Figures, or <a
    href="http://en.wikipedia.org/wiki/Hexagon">Hexagons</a>,
    and from thence rising in the number of their sides till
    they receive the honourable title of <a
    href="http://en.wikipedia.org/wiki/Polygon">Polygonal</a>,
    or many-Sided. Finally when the number of the sides
    becomes so numerous, and the sides themselves so small,
    that the figure cannot be distinguished from a <a
    href="http://en.wikipedia.org/wiki/Circle">circle</a>, he
    is included in the Circular or Priestly order; and this is
    the highest class of all.
    </p>
    and here's the jquery code
    Code:
    $(document).ready(function(){
      $('<a href="#top">back to top</a>')
        .insertAfter('div.chapter p');
      $('<a id="top" name="top"></a>')
        .prependTo('body');
    });
    when i ran the script, no "back to top" link after each paragraph appear

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    It works fine for me, when I add a closing </div> tag - does that fix it for you? Is there anything else on your page that might be interfering?

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question

    actually, it has a closing </div> tag, i just didn't include that in my first post because the whole test html code is very long..and no, it doesn't work, that's why i run in this forum and posted the question

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Well, I tried the code you posted and it worked. So my next guess would be that there's something on the page that's stopping it working.

  • #5
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Spudhead View Post
    Well, I tried the code you posted and it worked. So my next guess would be that there's something on the page that's stopping it working.
    nah.. my javascript is enabled ofcourse , there's should be something else, i just don't know what the hell was that LOL

  • #6
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    425
    Thanks
    10
    Thanked 62 Times in 61 Posts
    Probably old version of jquery?

    We could play long hangman game,
    if you couldn't post bit more of your code


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •