jQuery Tutorial Tutorials - jQuery .contents() method

jQuery .contents() method

The .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.

jQuery .contents() method Syntax

.contents()

jQuery .contents() method Example

example

Find 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>

Try now

Date:2019-08-26 13:23:15 From:www.Lautturi.com author:Lautturi