Return to Snippet

Revision: 65344
at November 21, 2013 11:33 by makbeta


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

Revision: 65343
at November 21, 2013 10:53 by makbeta


Initial Code
var $element = $('#my-element');
var $nodes = $element.contents();

Initial URL


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

Initial Title
JS:jQuery Get all nodes, including orphaned text

Initial Tags
jquery, text

Initial Language
jQuery