jQuery is()Method

jQuery HTML 方法jQuery Traversal Methods

Example

If the parent element of <p> is a <div> element, display an alert message:

if ($("p").parent().is("div")) {
alert("The parent element of p is div");
}

Try it Yourself »

Definition and Usage

The is() method checks whether a selected element matches a selector.


Syntax

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

Parameter Description
selectorElement Required. A selector expression used to check the matched element set against the selector/element/jQuery object. If there is at least one matching element, return true; otherwise, return false.
function(index,element)

Optional. Specifies a function to execute for the selected set of elements.

  • index - The index position of the element
  • element - The current element (the "this" selector can also be used)

jQuery HTML 方法jQuery Traversal Methods

Other Extensions