jQuery DOM Traversing Select children of element


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>

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");