Home > Web Front-end > JS Tutorial > How to use the find() method in jQuery

How to use the find() method in jQuery

清浅
Release: 2019-01-11 15:28:31
Original
6740 people have browsed it

The find() method in jQuery is used to return the descendants of the current element. You can return a single element or multiple elements by searching for the CSS class in the element, and you can return all elements through the * sign.

In jQuery There is a method that finds and returns all descendants of a selection. Descendants are elements located within the selected element. These elements can be children, children's children, children's children, etc. The method used to obtain the descendants of each element in the current element is find(), which mainly filters through selectors, jQuery objects or elements

How to use the find() method in jQuery

[Recommended courses: jQuery Tutorial

Usage of find() method

HTML code:

<div class="demo">
    <ul>
        <li>php中文网</li>
        <li>php中文网</li>
        <li class="findMe">php中文网</li>
        <li>php中文网</li>
        <li>php中文网</li>
    </ul>
</div>
Copy after login

(1) Find a single element:

$(".demo").find(".findMe").css("color", "pink");
Copy after login

Rendering:

How to use the find() method in jQuery

It can be seen from the rendering that only the third li has changed color

(2) in jQuery Separated by commas, return multiple child elements

$(".demo").find(".findMe1,.findMe2,.findMe3").css("color", "pink");
Copy after login

Rendering:

How to use the find() method in jQuery

(3) Return all descendant elements

You can return all descendant elements through the * sign

$(".demo").find("*").css("color", "pink");
Copy after login

Rendering:

Image 15.jpg

Summary: The above is about jQuery The use of the find() method, I hope it will be helpful to everyone

The above is the detailed content of How to use the find() method in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template