English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery is() Method

jQuery Traversal Methods

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.

Syntax:

Check element:

$(selector).is(selectorExpression)

Use function to check element:

$(selector).is(function(index, element))

Instance

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 Value

ParameterDescription
selectorExpressionSpecify 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
  • index-Return the index position of the element in the set

  • element-Return the current element

jQuery Traversal Methods