tags:

views:

311

answers:

2
+1  A: 

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
Not working as expected but at least prepends the text. basically i want to iterate through all div ("#panel") inside the accordion and that is working, and for each div("#panel") i would find, i would look for the elements with the class ("dmPageHeadline") and prepend " 1 - " to it but keeping the original html extracted from the div("#panel").
byte_slave
+1  A: 

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 :)

Nick Craver