![jQuery Tutorial](/jquery/images/jquery-mini-logo.jpg)
- jQuery Tutorial
- jQuery - Home
- jQuery - Overview
- jQuery - Basics
- jQuery - Syntax
- jQuery - Selectors
- jQuery - Events
- jQuery - Attributes
- jQuery - AJAX
- jQuery DOM Manipulation
- jQuery - DOM
- jQuery - Add Elements
- jQuery - Remove Elements
- jQuery - Replace Elements
- jQuery CSS Manipulation
- jQuery - CSS Classes
- jQuery - Dimensions
- jQuery - CSS Properties
- jQuery Traversing
- jQuery - Traversing
- jQuery - Traversing Ancestors
- jQuery - Traversing Descendants
- jQuery References
- jQuery - Selectors
- jQuery - Events
- jQuery - Effects
- jQuery - HTML/CSS
- jQuery - Traversing
- jQuery - Miscellaneous
- jQuery - Properties
- jQuery - Utilities
- jQuery Plugins
- jQuery - Plugins
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
- jQuery Useful Resources
- jQuery - Questions and Answers
- jQuery - Quick Guide
- jQuery - Useful Resources
- jQuery - Discussion
jQuery find() Method
The find() method in jQuery is used to search and return the descendant elements of the selected element.
The word "descendant" means to move in a downward direction. For example, In a family chain, "child" is a descendant of "parent" and he/she is a descendant of "Grandparent" and so on.
This method allows you to navigate through the descendants of DOM elements, reaching all the way down to the last descendant.
Syntax
Following is ths syntax of find() method in jQuery −
$(selector).find(filter)
Parameters
This method takes the following parameter −
filter: A selector expression, element or jQuery object to filter the search for descendants.
Note: If we want to return multiple descendants, we can seperate each expression with comma(,).
Example 1
In the following example, we are using the find() method to return all the <span> elements that are descendants of <div> element −
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style> .descendants * { display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px; } </style> <script> $(document).ready(function(){ $('div').find('span').css({"color": "red", "border": "1px solid red"}); }); </script> </head> <body class="descendants"> <div id="container">Great-Grandparent <ul>Grandparent <li>Parent <span>Child</span> </li> </ul> </div> </body> </html>
when we execute the above program, the <span> elements that are descendants of <div> element will have red color and red border to them.
Example 2
We can use the "*" selector to return all descendant elements of an element
In this example, we are using the "*" selector to return all the elements that are descendants of <ul> −
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style> .descendants * { display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px; } </style> <script> $(document).ready(function(){ $('ul').find('*').css({"color": "red", "border": "1px solid red"}); }); </script> </head> <body class="descendants"> <div id="container">Great-Grandparent <ul>Grandparent <li>Parent <span>Child</span> </li> </ul> </div> </body> </html>
When we execute the above program, all the elements (<li>, and <span>) that are descendants of <div> will be returned.
Example 3
We can separate each expression with a comma (,) to return multiple descendants.
In this example, we are returning multiple descendants of <div> element −
<html> <head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style> .descendants * { display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px; } </style> <script> $(document).ready(function(){ $('div').find('ul, li, span').css({"color": "red", "border": "1px solid red"}); }); </script> </head> <body class="descendants"> <div id="container">Great-Grandparent <ul>Grandparent <li>Parent <span>Child</span> </li> </ul> </div> </body> </html>
When we execute the above program, multiple elements (<ul>, <li>, and <span>) that are descendants of <div> will be returned.