Skip to content

Instantly share code, notes, and snippets.

@zhengjia
Created June 2, 2010 20:02
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 zhengjia/422901 to your computer and use it in GitHub Desktop.
Save zhengjia/422901 to your computer and use it in GitHub Desktop.
jquery content()
$('.container').contents().filter(function() {
return this.nodeType == 3;
})
.wrap('<p></p>')
.end()
.filter('br')
.remove();
#http://api.jquery.com/contents/
#This code first retrieves the contents of <div class="container"> and then filters it for text nodes, which are wrapped in paragraph tags. This is accomplished by testing the .nodeType property of the element. This DOM property holds a numeric code indicating the node's type; text nodes use the code 3. The contents are again filtered, this time for <br /> elements, and these elements are removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment