.contents()
methodThe .contents()
method in jQuery is used to create a new jQuery object that contains the children of each matched elements,including the comment and text nodes.
.contents()
method Syntax.contents()
.contents()
method ExampleFind out all the text nodes inside a paragraph and wrap them with a bold tag.
HTML
<p>Hello<span id="brand">Lautturi</span></p>
jQuery
$('p').contents(); $('p').contents().wrap( "<b></b>" );
Result
[Hello<span id="brand">Lautturi</span>] <b>Hello</b><b><span id="brand">Lautturi</span></b>