jQuery find() method
Example
Return
-
all of the descendants element:
- li (child) span (grandchild)
$(document).ready(function(){
$("ul").find("span").css({"color":"red","border":"2px solid red"});
});
Result:
body (great-grandparent)
div (grandparent)
Try it »
Definition and Usage
The find() method returns the descendant elements of the selected element.
Descendants are children, grandchildren, great-grandchildren, and so on.
**DOM Tree:** This method traverses down along all paths of the DOM element's descendants to the last descendant (). If you only need to traverse a single level down the DOM tree (returning direct child elements), use children() method.
**Note:**filter The parameter is required in the find() method, unlike other tree-traversal methods.
**Tip:** To return all descendant elements, use the "*" selector.
Syntax
$(
selector
).find(
filter
)
| Parameters | Description |
|---|---|
| filter | Required. A selector expression, element, or jQuery object that filters the search for descendants. |
**注意:**如需返回多个后代,请使用逗号分隔每个表达式。 |
More examples
Return all descendant elements of the
Use the "*" selector to return all descendant elements of the element.
-
all of the descendants Element
How to return
-
all of the descendants .
only select descendants with the given class name
How to return descendant elements with class name "1".
Return multiple descendants
How to return multiple descendant elements.
-
jQuery collection of elements to filter the descendant search
How to return via a jQuery object
-
all of the descendants of the element .
Demonstrate descendants of an element by tag name
Demonstrate
jQuery Traversal Methods