Posted By

makbeta on 11/21/13


Tagged

jquery text nodes


Versions (?)

JS:jQuery Get all nodes, including orphaned text


 / Published in: jQuery
 

Reads all the nodes of the object, including orphaned text that's not wrapped into any tag as well as empty text nodes

  1. var $element = $('#my-element');
  2. var $nodes = $element.contents();
  3. $nodes.each(function() {
  4. if(this.nodeType === 3 && $.trim($(this).text())) {
  5. $(this).wrap('<span class="orphan" />');
  6. }
  7. });

Report this snippet  

You need to login to post a comment.