Home >>jQuery Tutorial >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 | 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.
|
<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>
Click me to find parent in a div element