Basic Methods and Properties

These are the basic methods and properties of jQuery objects. They don’t alter the selection or the selected elements in any way, but they allow you to query and iterate over the set of selected elements. See the section Queries and Query Results for details.

context

The context, or root element, under which the selection was made. This is the second argument to $() or the Document object.

each(f(idx,elt))

Invokes f once as a method of each selected element. Stops iterating if the function returns false. Returns the jQuery object on which it was invoked.

get(idx):eltget():array

Return the selected element at the specified index in the jQuery object. You can also use regular square bracket array indexing. With no arguments, get() is a synonym for toArray().

index():intindex(sel):intindex(elt):int

With no argument, return the index of the first selected element among its siblings. With a selector argument, return the index of the first selected element within the set of elements that match the selector sel, or -1 if it is not found. With an element argument, return the index of elt in the selected elements, or -1 if it is not found.

is(sel):boolean

Returns true if at least one of the selected elements also matches sel.

length

The number of selected elements.

map(f(idx,elt)):jQuery

Invokes f once as a method of each selected element, and returns a new jQuery object that holds the returned values, with null and undefined values omitted and array values flattened.

selector ...

Get jQuery Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.