Skip to content

Instantly share code, notes, and snippets.

@dieseltravis
Created July 15, 2009 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dieseltravis/147952 to your computer and use it in GitHub Desktop.
Save dieseltravis/147952 to your computer and use it in GitHub Desktop.
jQuery example that gets/sets text nodes in html
// jQuery example that gets/sets text nodes in html
// wrap all direct child text nodes
$html.contents().filter(function() {
//Node.TEXT_NODE === 3
return (this.nodeType === 3);
}).each(function () {
this.nodeValue = $.trim(this.nodeValue);
if (this.nodeValue.length > 0) {
$(this).wrap("<p></p>");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment