jQuery .find()

jQuery .find() gets all the descendants of each element in the current set of matched elements, filtered by a selector; Also check jQuery .children() if you need to get only first level of depth;

js:


$('ul').find('li.target')

    .css('background-color', 'yellow')

    .append(' <span class="label label-info">.target</span>');​

html:


<ul>

<li>list item</li>

<li>list item

<ul>

<li>list item</li>

<li class="target">list item with target class</li>

<li>list item</li>

</ul>

</li>

<li class="target">list item with target class</li>

<li>list item</li>

<li>list item

<ul>

<li>list item</li>

<li class="target">list item with target class</li>

<li>list item</li>

</ul>

</li>

<li>list item</li>

<li class="target">list item with target class</li>

</ul>​

Leave a Comment