back to Overview

.is()

Checks whether all elements in the list match the given selector.
Web module only.

Syntax Variants

list.is()
list.is(selector)
list.is(filterFunc)

Parameters

selector (optional)
any selector valid for $(), including CSS selectors and lists.
Selectors are optimized for '*', '.classname', 'tagname' and 'tagname.classname'. The performance for other selectors is relative to the number of matches for the selector in the document. Default is '*', which checks whether all list items are HTML elements.
filterFunc
a function(node) returning true for those nodes that are approved.
(return value)
true if all list elements match the selector. false otherwise.

Description

Checks whether all elements in the list match the given selector. Returns true if they all do, or false if at least one does not.

One common use for is() is to check whether an element has a certain CSS class.

Please note that this method is optimized for the four simple selector forms '*', '.classname', 'tagname' and 'tagname.classname'. If you use any other kind of selector, be aware that selectors that match many elements in the document can be slow.

Example

Checks whether the element has the class 'myClass':

var isMyClass = $('#myElement').is('.myClass');

Example

Checks whether the list contains only table rows:

var areRows = $('.myRows').is('tr');

See also..

  • only() removes elements from a list that do not match a selector.

Comments

comments powered by Disqus

back to Overview

Functions