jQuery Selectors


Selector Example Description
* $("*") Every component
#id $("#lastname") The element having the id="lastname" attribute.
.class $(".intro") Every element with the class="intro"
.class,.class $(".intro,.demo") All items with the class "intro" or "demo" are included.
element $("p") Every <p> element
el1,el2,el3 $("h1,div,p") Every <h1>, <div>, and <p> element
 
:first $("p:first") The very first <p> element
:last $("p:last") The last <p> element
:even $("tr:even") Every even <tr> element
:odd $("tr:odd") All <tr> components that are odd
 
:first-child $("p:first-child") All <p> components that are the parent's first child.
:first-of-type $("p:first-of-type") All <p> elements that are the parent's initial p element.
:last-child $("p:last-child") All <p> components that are the parent's final child.
:last-of-type $("p:last-of-type") All <p> elements that are the parent's final p element.
:nth-child(n) $("p:nth-child(2)") All <p> components that are the parent's second child.
:nth-last-child(n) $("p:nth-last-child(2)") All <p> components that are the second child of their parent, starting with the oldest.
:nth-of-type(n) $("p:nth-of-type(2)") All <p> elements that are the parent's second p element.
:nth-last-of-type(n) $("p:nth-last-of-type(2)") All <p> elements that are their parent's second p element, starting with the final child.
:only-child $("p:only-child") All <p> components that are the parent's only child.
:only-of-type $("p:only-of-type") All <p> components that are the lone child of their parent's type.
 
parent > child $("div > p") All <p> elements that are children of a div element
parent descendant $("div p") All <p> elements that are children of a div element
element + next $("div + p") The <p> elements that follow each div element
element ~ siblings $("div ~ p") All <p> items that follow the div element
 
:eq(index) $("ul li:eq(3)") The fourth item in a list (index begins at 0).
:gt(no) $("ul li:gt(3)") Elements in the list with an index greater than 3
:lt(no) $("ul li:lt(3)") List entries with indexes fewer than three
:not(selector) $("input:not(:empty)") Every input element that is not empty
 
:header $(":header") All of the header components <h1>, <h2>…<h6>
:animated $(":animated") All of the components are animated.
:focus $(":focus") The aspect that is now under consideration.
:contains(text) $(":contains('Hello')") All items containing the word "Hello"
:has(selector) $("div:has(p)") All <div> elements have a <p> element.
:empty $(":empty") All components that are not filled.
:parent $(":parent") Every element that is the parent of another element.
:hidden $("p:hidden") All <p> elements that are concealed.
:visible $("table:visible") All tables that are displayed.
:root $(":root") The root element of the document.
:lang(language) $("p:lang(de)") All <p> elements with lang attribute values that begin with "de"
 
[attribute] $("[href]") All elements that have the href property.
[attribute=value] $("[href='default.html']") All items having the href attribute set to "default.html".
[attribute!=value] $("[href!='default.html']") All items whose href attribute value is not "default.html".
[attribute$=value] $("[href$='.jpg']") All items with href attribute values that finish in ".jpg".
[attribute|=value] $("[title|='Tomorrow']") All items that have a title attribute value of 'Tomorrow' or that begin with 'Tomorrow' followed by a hyphen.
[attribute^=value] $("[title^='Tom']") All items with title attribute values beginning with "Tom"
[attribute~=value] $("[title~='hello']") All items having the exact word "hello" in their title attribute value.
[attribute*=value] $("[title*='hello']") All items have the word "hello" in their title attribute value.
 
:input $(":input") Every input element.
:text $(":text") All input elements have the type="text" attribute.
:password $(":password") All input elements have the type="password" attribute.
:radio $(":radio") All input elements have the type="radio" attribute.
:checkbox $(":checkbox") All input elements have the type="checkbox" attribute.
:submit $(":submit") All input elements have the type="submit" attribute.
:reset $(":reset") All input elements have the type="reset" attribute.
:button $(":button") All input elements have the type="button" attribute.
:image $(":image") All input elements have the type="image" attribute.
:file $(":file") All input elements have the type="file" attribute.
:enabled $(":enabled") All input components that are enabled.
:disabled $(":disabled") All input elements are disabled.
:selected $(":selected") All of the input components that were chosen.
:checked $(":checked") All input components were checked.