Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery is() method

jQuery is() method

jQuery HTML Methods jQuery Traversal Methods

Example

If both the

the parent element of the, is

element, pop up an alert message:

if ($("p").parent().is("div")) {

    alert("the parent of p is div");

}

Try it »


Definition and usage

The is() method is used to check whether the selected element matches a selector.


Syntax

$(

selector

).is(

selectorElement,

function

(index

,

element)

)

Parameters Description
selectorElement Required. A selector expression that checks the set of matched elements against the selector/element/jQuery object; returns true if at least one matching element exists, otherwise returns false
function(index,element)

Optional. Specifies a function to execute on the group of selected elements.

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

    jQuery HTML Methods jQuery Traversal Methods