jQuery Tutorial Tutorials - jQuery .find() method

jQuery .find() method

The .find(selector) method in jQuery is used to filter the descendants of each element in the current set of matched elements by a selector, jQuery object, or element.

jQuery .find() method Syntax

.find(selector)
.find(element)

jQuery .find() method Example

Begins with the current element,searches through their descendants step by step,return all matching elements.

example

Finds matching element and highlight them.

HTML

<ul>
    <li class="category">Language
        <ul>
            <li class="lang">Java
                <ul>
                    <li>Java tutorial</li>
                    <li>Java Examples</li>
                </ul>
            </li>
            <li class="lang">Python
                <ul id="python">
                    <li>Python tutorial</li>
                    <li id="pyex">Python Examples</li>
                </ul>
            </li>
        </ul>
    </li>
    <li class="category">Tools</li>
    <li class="category">Lautturi</li>
</ul>

jQuery

$("#python").find('li').css('background','cyan');
// return all matched elements ,not only the first.
// [<li>,<li id="pyex">]

$(".category").find('#pyex').css('background','cyan'); 
// [<li id="pyex">]

var item = $( ".lang" )[0];
$(".category").find(java).css('background','cyan');
// [<li class="lang">Java]

Try now

Date:2019-08-26 13:32:10 From:www.Lautturi.com author:Lautturi