When you want to perform actions on specific DOM element, you basically need to search that element(s) first. jquery find makes this task easier for you.
find() function takes selector expression as a parameter and then it searches for an element which needs to be matched with a given expression.
In the below code, we will try to colour code elements in the unordered list in HTML using jQuery find.
Let’s go through code,
Then, we are passing an expression (li.Teacher) to the $. It means to look the li element with Teacher class and then inside Teacher element using jquery find function find all il elements and apply CSS to it. Similar we are doing for Clerk element.
.css() is applying colour to element(s) that have been found by .find() function.
We hope you have understood how .find() works in jQuery. Please drop a comment in below comment box if you have any doubts. In future articles, we will explore other parts of jQuery.