Getting text nodes using jQuery
It just takes a little extra work to filter a node's contents based on their type:
$node.contents().filter(function() {
//Node.TEXT_NODE === 3
return (this.nodeType === 3);
}).each(function () {
// for each text node, do something with this.nodeValue
});
Fork the gist: https://gist.github.com/147952
Written by travis
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#