2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How do I select text nodes with jQuery?

Iam trying to get all descendant text nodes of an element, as a jQuery collection. 

How do i do it ?

userimage

And here the solution for you,


$(elem)
  .contents()
  .filter(function() {
    return this.nodeType === 3; //Node.TEXT_NODE
  });

Answer is