Home >>jQuery Tutorial >jQuery find() Method

jQuery find() Method

jQuery find() Method

jQuery find() method in jQuery is used to returns descendant elements of the selected element. It can be a child, grandchild, great-grandchild, and so on.

Syntax:
$(selector).find(filter)

Parameter Values

Parameter Description
filter It is a required parameter and is used for a selector expression, element or jQuery object to filter the search for descendants
Here is an Example of jQuery find() Method:

<html>
<head>
<style>
.ancestors * { 
display: block;
border: 2px solid lightgrey;
color: lightgrey;
padding: 5px;
margin: 15px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("ul").find("span").css({"color": "dodgerblue", "border": "2px solid #df65f7"});
});
</script>
</head>
<body>
<div class="ancestors">
<div style="width:500px;">div (grandparent)
<ul>ul (direct parent)  
<li>li (child)
<span>span (grandchild)</span>
</li>
</ul>   
</div>
</div>
</body>
</html>

Output:
div (grandparent)
    ul (direct parent)
  • li (child) span (grandchild)