views:

1865

answers:

1

I am trying to prepend something to a li, hosted inside a #container #boxes #third li a but it isn't quite working.

I am using the following code:

$('#container #boxes #third li a').append(kevintext);

But whenever I do that, nothing happens. You can see the code in action at my testing page here.

Because that didn't work, I tried something else: to replace a span inside my footer with other text (so people with JavaScript disabled won't see "hover over me" and try to hover).

I used the following code:

$('#footer span').replaceWith('<i>For design info, mouse over me.</i>');

That didn't work either, so I am thinking this probably has something to do with my code, and possibly one fix will solve both problems?

Please help.

+2  A: 

What you have should work. The main reason it probably isn't is because (at least by the quick look I took at assets/script.js) you are trying to run this outside of $(document).ready() - without wrapping your code in this function (which you did do for another part) the elements will not have been created yet, so at that point nothing will happen.

Paolo Bergantino
+1 - Makes sense
karim79
Oh; I always thought that once document.ready was ran, it meant the page was finished and therefore you couldn't add anything to it.
Brandon Wang
That would make a lot of websites out there impossible to do :) All document.ready does is wait for the DOM tree to be ready so you can do selections on the elements in your page. Since you're adding content in a specific place, you have to wait for the DOM to be ready so you can find the specific place.
Paolo Bergantino