Web Development with jQuery®

(Elliott) #1

(^494) ❘ APPENDIX B JQUERY SELECTORS
bapp02.indd 02/17/2015 Page 494
CONTEXT FILTERS
The following selectors are applied based on the context elements that appear in the
document.
:root Selects the root element of the document; in an HTML
document this will be the element. In an XML
document, it will be whatever name is given the root
element.
:first Selects the fi rst element that occurs in the selection.
:last Selects the last element that occurs in the selection.
:not(selector) Reduces a selection by specifying what you want to
exclude from a selection.
:even Selects only elements falling within even numbering.
jQuery calculates position, offset from zero. Item one
would be considered number zero, item two would be
considered number one, and so on; so :even matches
numbers 0, 2, 4, and so on.
:odd Selects only elements falling within odd numbering.
jQuery calculates position offset from zero. Item one
would be number 0, item two would be number 1; so
:odd matches numbers 1, 3, 5, and so on.
:eq(index) Selects a single element based on its offset in the selec-
tion counting from 9; for example, :eq(0) matches the
fi rst item in the selection, :eq(1) matches the second
item in the selection, and so on.
:gt(index) Selects all elements where each element’s offset is
greater than the number specifi ed. Specifying :gt(4)
selects elements with offset 5 or greater, where the
count is offset from 0.
:lt(index) Selects all elements where each element’s offset is less
than the number specifi ed. For example, specifying
:lt(4) would select element’s with offset 0, 1, 2, and
3.
:header Selects all elements that are headers, for example, h1,
h2, h3, h4, h5, or h6.
:animated Selects all elements that are currently animated.
:lang("en")
:lang("en-us")
Selects all elements of the specifi ed language, such as


or
.
[http://www.it-ebooks.info](http://www.it-ebooks.info)