Created
June 2, 2010 20:02
-
-
Save zhengjia/422901 to your computer and use it in GitHub Desktop.
jquery content()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.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