Home >>jQuery Tutorial >jQuery is() Method

jQuery is() Method

jQuery is() Method

jQuery is() method is used to checks if one of the selected elements matches the selectorElement.

Syntax:
$(selector).is(selectorElement,function(index,element))

Parameter Values

Parameter Description
selectorElement It is a Required parameter and is used to specifies a selector expression, element or a jQuery object to match the current set of elements.
function(index,element) It is an Optional parameter and is used to specifies a function to run for the group of selected elements.
  • index – Used to the index position of the element
  • element -it is used to the current element (the "this" selector can also be used)
Here is an Example of jQuery is() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".txt").click(function(){
if ($(".txt").parent().is(".box")) {
alert("Parent of p is div"); 
}
});
});
</script>
</head>
<body>
<div class="box">
<p class="txt">Click me to find parent in a div element</p>
</div>
</body>
</html>

Output:

Click me to find parent in a div element


No Sidebar ads