English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The is() method checks if one of the selected elements matchesselectorExpressionMatch.
If at least one of these elements matches the given parameter, the is() method will return true, otherwise it will return false.
Check element:
$(selector).is(selectorExpression)
Use function to check element:
$(selector).is(function(index, element))
Check if the parent of <p> is a <div> element:
$(document).ready(function(){ $("p").parent().is("div"); });Test and see‹/›
Another example of using the is() method:
$("li").click(function () { if($(this).is(":first-child")){ $("p").text("List item 1"); } else if ($(this).is(".middle")){ $("p").text(".middle class list item"); } else if ($(this).is(":contains('item 3');"){ $("p").text("List item3"); } });Test and see‹/›
Parameter | Description |
---|---|
selectorExpression | Specify a selector expression, jQuery object, or element to match the current element set |
function(index, element) | Specify a function to be used to test each element in the set
|