PDA

View Full Version : jquery prependTo() doesn't work ?


capt_nemo777
03-08-2010, 10:48 AM
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

<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

$(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 :confused:

Spudhead
03-08-2010, 12:34 PM
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?

capt_nemo777
03-08-2010, 12:43 PM
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 :(

Spudhead
03-08-2010, 04:48 PM
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.

capt_nemo777
03-08-2010, 11:28 PM
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

hdewantara
03-09-2010, 06:19 PM
Probably old version of jquery?

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