aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes selecting pure text in jquery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "selecting pure text in jquery" Watch "selecting pure text in jquery" New topic

selecting pure text in jquery

jeroen dijkmeijer
Ranch Hand

Joined: Sep 26, 2003
Posts: 131

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,
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62272

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Nov 08, 2001
Posts: 15383
Why do you need to do this with JavaScript. Can;t you do this on the serverside to start out with?

I agree. Here's the link:
subject: selecting pure text in jquery