Last Updated: February 25, 2016
·
2.88K
· dieseltravis

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

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
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