File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "selecting pure text in jquery" Watch "selecting pure text in jquery" New topic
Author

selecting pure text in jquery

jeroen dijkmeijer
Ranch Hand

Joined: Sep 26, 2003
Posts: 131
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

Joined: Jan 10, 2002
Posts: 60822
    
  65

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
Author
Rancher

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
author
Rancher

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

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: selecting pure text in jquery
 
Similar Threads
jQuery -- add remove list item
CSS not working in Firefox, works in IE
Menu image positioning
List item disappears in Firefox
javascript dropdown over text field