Skip to content

Instantly share code, notes, and snippets.

@eimfach
Last active October 27, 2015 11:33
Show Gist options
  • Save eimfach/27731dd63f750de5cbf1 to your computer and use it in GitHub Desktop.
Save eimfach/27731dd63f750de5cbf1 to your computer and use it in GitHub Desktop.
//filter textnodes wrap then in p and remove all br elements
$($element.contents()).filter(function(){
this.textContent = _.trim(this.textContent); // trim trailling and leading white spaces
return this.nodeType === 3; // filter textnodes only
}).wrap('<p></p>').end().filter('br').remove();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment