jQuery | is() Method
The is() method is used to check if one of the selected elements matches the selectorElement.
Syntax:
$(selector).is(selectorElement, function(index, element))
Parameters: This method accepts parameters above mentioned and below described:-
- selector: It is an optional parameter. It specifies the selector from which event will remove.
- selectorElement: It is a required parameter which specifies a selector expression, element or a jQuery object to match the current set of elements against. It returns true if there is at least one match from the given argument, and false if not.
- function(index, element): It is an optional parameter which specifies a function to run for the group of selected elements.
- index: the index position of the element
- element: the current element (the “this” selector can also be used)
Below example illustrate the is() method in jQuery:
Example:
<!DOCTYPE html> <html> <head> <script src= </script> <script> $(document).ready(function() { $("p").click(function() { if ($("p").parent().is("div")) { alert("Parent of p is div"); } }); }); </script> </head> <body> <center> <h1>GeeksforGeeks</h1> <div> <p>Click me to find out if I my parent is a div element.</p> </div> </center> </body> </html> |
chevron_right
filter_none
Output:
Before:

After:

Recommended Posts:
- jQuery | before() Method
- jQuery | add() method with Example
- jQuery | get() Method
- jQuery | off() Method
- jQuery | die() Method
- jQuery | param() Method
- jQuery | ajaxStart() Method
- jQuery | $.proxy() Method
- jQuery | fadeToggle() Method
- jQuery | slideToggle() Method
- jQuery | live() Method
- jQuery | text() Method
- jQuery | error() Method
- jQuery | Misc get() Method
- jQuery | append() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



