I would like to get all descendant text nodes of an element, as a jQuery collection. What is the best way to do that?
I would like to get all descendant text nodes of an element, as a jQuery collection. What is the best way to do that?
Jauco posted a good solution in a comment, so I'm copying it here:
$(elem)
.contents()
.filter(function() {
return this.nodeType === 3; //Node.TEXT_NODE
});