• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

selecting pure text in jquery

 
jeroen dijkmeijer
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a nested list and I would like to put span tags around the text of the headers of sublists.


this should become:



I've tried a few things already:

But this puts a span around the text and the UL tag.


this gives an error (text()) is not a function



doesn't work at all No error no output.

I'm a bit mystified hopefully somebody here can help me.
kind regards,
Jeroen.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Text nodes are special in the DOM -- the wrap functions can only work with element nodes. I'd recommend fetching the text contents, creating a new span with those contents, and then replacing the old contents with the new span element.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd also ask *why* you want to put a span around them--might it be better to add a class to the list element of the header items?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to do this with JavaScript. Can;t you do this on the serverside to start out with?

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic