/ 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
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var $element = $('#my-element'); var $nodes = $element.contents(); $nodes.each(function() { if(this.nodeType === 3 && $.trim($(this).text())) { $(this).wrap('<span class="orphan" />'); } });
Comments
