The jQuery selectors are important aspects of the jQuery library. The jQuery selectors allow page elements to be selected. It supports selection of single element or multiple elements. These selectors use CSS syntax which allows identifying set of elements to operate upon with jQuery library methods. The important purpose of jQuery selector is to select elements and perform some actions on the selected elements. The jQuery selectors searches or selects HTML elements and performs intended action on those elements. jQuery selectors is one of the most powerful mechanism used in jQuery to search the elements. This concept is borrowed from the CSS language.
A selector identifies HTML element which will manipulate with jQuery code. A jQuery selector uses expressions to find out matching elements in the set of matched elements from the DOM. All types of jQuery selectors start with dollar sign and parentheses. i.e. $( ).
The table shows list of jQuery selectors with description.
Selector | Description |
---|---|
(“*”) | It selects all the elements. |
(“#id”) | It selects elements by ID attribute. |
(“.class”) | It selects elements by class name. |
tag | It selects all the p elements. |
:first-child selector | It selects first matched element of their parent element on the page. |
:last-child selector | It selects last matched element of their parent element on the page. |
:not selector | It selects all the elements except the specified element that do not match given selector. |
:gt() selector | It returns all the elements which are greater than index value. |
:lt() selector | It returns all the elements which are less than index value. |
:even selector | It selects all the elements that have even index value. |
:odd selector | It selects all the elements that have odd index value. |
:enabled selector | It selects all the elements that are enabled. |
:disabled selector | It selects all the disabled elements. |
:selected selector | It selects all the elements that are in selected state. |
:checked selector | It selects all the elements that are checked or selected. |
:input selector | It selects all the input elements from input, select, textarea, button elements. |
:text selector | It selects all the elements that are of type text. |
:button selector | It selects all the elements that are of type button. |
:has selector | It selects all the elements with a descendant that matches specified selector. |
:password selector | It selects all the elements that are of type password. |
:radio selector | It selects all the elements that are of type radio. |
:checkbox selector | It selects all the elements that are of type checkbox. |
:image selector | It selects all the elements that are of type image. |
:file selector | It selects all the elements that are of type file. |
:submit selector | It selects all the elements that are of type submit. |
:reset selector | It selects all the elements that are of type reset. |
:animated selector | It selects all the elements that are under animated control. |
:header selector | It selects all the headers from h1 through h6. |
:hidden selector | It selects all the hidden elements. |
:visible selector | It selects all the visible elements. |
:empty selector | It selects all the elements which have no child elements. |
:parent selector | It selects all the elements that are parent to other elements including text nodes. |
:contains selector | It selects all the elements that contains the text. |
[attribute] | It selects all the elements that have attribute name or attribute value. |
[attribute$=value] | It selects all the elements that ends with a given string. |
[attribute=value] | It selects all the elements that equal to a certain value. |
[attribute*=value] | It returns all the elements that passed attribute value contains the passed value. |
[attribute!=value] | It selects all the elements that do not equal to certain value. |