Javascript examples for jQuery Method and Property:is
The is() method checks if one of the selected elements matches the selectorElement.
Parameter | Require | Description |
---|---|---|
selectorElement | Required. | a selector expression, element or a jQuery object. |
function(index,element) | Optional. | a function to run for the group of selected elements. |
If the parent of <p> is a <div> element, alert some text:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").click(function(){ if ($("p").parent().is("div")) { console.log("Parent of p is div"); }/* ww w . j ava 2 s .co m*/ }); }); </script> </head> <body> <div> <p>click me and check console</p> </div> </body> </html>