Last Updated: February 25, 2016
·
2.613K
· 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