I'm just starting to dig into jQuery, and was wondering whether anyone would have an idea how to implement a selector that would return text nodes.
For example, something like "#text", which is Mozilla's name for text nodes[1], or "text()", which is an xpath selector[2] (realizing of course that the former would overlap lookups by node ID). This would allow folks to do something like $("#text").wrap("<span></ span>"), to wrap all text nodes in a span. I understand that allowing users to select text nodes may be dangerous, since some jQuery methods would not be possible on selected text nodes without modification (such as "addClass", et cetera). But I would love to give a shot at implementing this as a plug-in, since I think it fits well with jQuery's idea of putting a lot of the smarts in selectors, not functions. Since characters : text :: nodes : node list, I think a lot of the existing logic could be re-used (allowing, for example, ":first- child" to return the first character of a text node). Is this possible? Or is it undesirable for some reason (speed/ complexity)? My alternative for now is to crawl the DOM and put every character in it's own span node, so any ideas/feedback would be appreciated. Jed Schmidt [1] http://developer.mozilla.org/en/docs/DOM:element.nodeName#Notes [2] http://www.w3.org/TR/xpath#node-tests