How do I select text nodes with jQuery?

Viewed 180338

I would like to get all descendant text nodes of an element, as a jQuery collection. What is the best way to do that?

11 Answers

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
  });
Related