It because prepend
expects either HTML, CSS selector, DOM Node or jQuery object. Try this instead:
$(x).find(".dmPageHeadline").prepend (document.createTextNode(" 1 - "));
K Prime
2010-01-08 10:47:50
It because prepend
expects either HTML, CSS selector, DOM Node or jQuery object. Try this instead:
$(x).find(".dmPageHeadline").prepend (document.createTextNode(" 1 - "));
In your code you have #panel
and you say you're looping through them...this shouldn't be the case though, an ID needs to be unique, otherwise you'll get all sorts of weird or non-existent behavior.
Instead give the elements a class="panel"
instead of id="panel"
. As for the jQuery side, you can simplify it down to:
$(".preview .panel .dmPageHeadline").prepend(" 1 - ");
Here's a working example of this in action
If you wanted the index to climb, then do something like this:
$(".preview .panel .dmPageHeadline").each(function(i) {
$(this).prepend(" " + i + " - "); //maybe (i+1) if you want 1 and not 0 first.
});
The .prepend()
function can take a string, it's just the way you were prepending that was a little odd :)