jQuery Tutorial Tutorials - jQuery .children() method

jQuery .children() method

The .children(selector) method in jQuery is used to create a new jQuery object that contains the children nodes of each matched elements,not including the comment and text nodes,optionally filtered by a selector

jQuery .children() method Syntax

.children([selector])

jQuery .children() method Example

example

Find out all the children of each paragraph and wrap them with a bold tag.

HTML

<p>Hello<span id="brand">Lautturi</span></p>

jQuery

$('p').children();

$('p').children().wrap( "<b></b>" );

Result

[<span id="brand">Lautturi</span>]

<b><span id="brand">Lautturi</span></b>

Try now

jQuery .children(selector) method Example

example

Find all children with a class "selected" of each div.

HTML

<div>
    <p>java tutorial</p>
    <p>learn javascript</p>
    <p class="selected">learn jquery</p>
    <p>python tutorial</p>
    <p class="selected">PHP</p>
</div>

jQuery

$("div").children(".selected")

Result

[<p class="selected">learn jquery</p>,<p class="selected">PHP</p>]

Try now

Date:2019-08-26 13:18:58 From:www.Lautturi.com author:Lautturi