Here's what I've come up with: jQuery.fn.extend({ textNodes: function() { return jQuery( jQuery.map( this, function(n){ return jQuery.grep(n.childNodes, function(n) { return n.nodeType == 3; }); }) ); } });
I love how succinct jQuery can be, but given how long I worked on this, it's kinda frustrating how it makes everything look so easy... Jed Schmidt On Aug 12, 1:23 am, Jed Schmidt <[EMAIL PROTECTED]> wrote: > Thanks for the tip, John. > > Maybe I don't quite grok it, but could it handle cases like this? > > <div>This is <b>bold</b>.</div> > > It seems to me that innerWrap could give me this: > > <div><span>This is <b><span>bold</span></b>.</span></div> > > but what I'm really after is this: > > <div><span>This is </span><b><span>bold</span></b><span>.</span></div> > > In other words, I'm looking for a way to manipulate all text nodes > themselves, regardless of whether they are the sole children of their > parent node. Since jQuery ignores text nodes, I think I would have to > use a custom traverse function instead. Does this make sense? > > Jed Schmidt > > On Aug 12, 12:50 am, "John Resig" <[EMAIL PROTECTED]> wrote: > > > How about using > > innerWrap?http://blog.brandonaaron.net/2007/06/04/jquery-snippets-innerwrap/ > > > --John > > > On 8/11/07, Jed Schmidt <[EMAIL PROTECTED]> wrote: > > > > Looking into the jQuery source, it seems like this would be pretty > > > daunting ("nodeType == 1" is checked in 5 different places, making it > > > seem like a non-trivial fix). > > > > Perhaps the next best bet after a proper selector would be a function > > > that, for each matched element, adds the jQuery objects for itstext> > > > nodechildren, and then removes the original element. Can something > > > like this be done in jQuery? > > > > Thanks again for any advice, > > > > Jed Schmidt