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
[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>
(1) Find a single element:
$(".demo").find(".findMe").css("color", "pink");
Rendering:
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");
Rendering:
(3) Return all descendant elements
You can return all descendant elements through the * sign
$(".demo").find("*").css("color", "pink");
Rendering:
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!