jQuery Select children of element


Example

To select the children of an element you can use the children() method.

<div class="parent">
    <h2>A headline</h2>
    <p>Lorem ipsum dolor sit amet...</p>
    <p>Praesent quis dolor turpis...</p>
</div>

Change the color of all the children of the .parent element:

$('.parent').children().css("color", "green");

The method accepts an optional selector argument that can be used to filter the elements that are returned.

// Only get "p" children
$('.parent').children("p").css("color", "green");