jQuery find() Method
Example
Returns all <span> elements that are descendants of <ul>:
Result:
- li (child)
Definition and Usage
The find() method returns descendant elements of the selected element.
Descendants are the children, grandchildren, great-grandchildren, and so on.
DOM Tree: This method traverses down the DOM elements' descendants until it reaches all paths to the last descendant (<html>). If you only need to traverse a single level down the DOM tree (to return direct children), use the children() method.
Note: The filter parameter is required in the find() method, unlike other tree traversal methods.
Tip: To return all descendant elements, use the "*" selector.
Syntax
| Parameter | Description |
|---|---|
| filter | Required. A selector expression, element, or jQuery object to filter the search for descendants. <br> <br> Note: To return multiple descendants, separate each expression with a comma. |
More Examples
Return all descendant elements of <html>
Return all <span> elements that are descendants of <ul>
Select only descendants with a given class name
Filter descendant search through a jQuery collection of all <ul> elements
Demonstrate descendants of elements by tag name