jQuery find() Method

The jQuery find() method can be used to get all the matching descendant elements for the selected element. When you use this method, it traverses through all its children and grandchildren to get the required element.

jQuery find() Method

Syntax

The syntax of this method is given below:-

Syntax
$(selector).find(filterElement)

Description of the Parameters

The description of these parameters is given below.

Parameter Name Description
selector Specify the element to select and find all its descendant elements. You can use the element tag name, class name, or id to select. It is a required field.
filterElement It is the element or jQuery object to specify and get the descendant element. It is a required field.

jQuery find() Method to Find Descendant an Element

If you want to get the specified descendant elements for the selected element, you have to use the method as given below. The below example contains the list of items and the span element. It finds all the span elements for the selected element.

You can also use the class name or id to select the required element.

Example

Test it Live

Output

  • First li element
  • Second li element.
  • Last li element.


When you click the button given above, it selects the descendant span element. After selecting the element, it applies the orange color.

Return All Descendant Elements

If you want to find all the descendant elements of the selected element, you have to use “*” as the parameter of the jQuery find() method. It selects every element that comes as the children and grandchildren of the selected element.

Example

Test it Live

Output

  • First li element
  • Second li element.
  • Last li element.


Click the button given above to find all the elements in the selected element. You can check all the elements highlighted with the border color.

How to Get Multiple Descendant Elements Using jQuery find() Method

You can also get multiple specified descendant elements for the selected element. Pass the multiple comma-separated tag name, class name, or id of the elements to get. The below example selects three descendant elements that are the children of the selected element.

Example

Test it Live

Output

  • Welcome to TutorialDeep!
  • Learn jQuery with live examples.
  • Use examples on your project
  • This is the Last li element.


When you click the button given above, it select italic, bold, and span element for the selected element.

You may also like to read

I hope you like this tutorial on jQuery find() method. If you have any queries regarding the tutorial, please comment below.

References