jQuery selector
jQuery Selectors
jQuery Selectors
Please use our jQuery Selector Detector to demonstrate different selectors.
Selector | Instance | Select |
---|---|---|
* | $(" *") | All elements |
#id | $("#lastname") | Element with id="lastname" |
.class | $(".intro") | class="intro " All elements of |
.class,.class | $(".intro,.demo") | All elements with class "intro" or "demo" |
element | $("p") | All<p> elements |
el1,el2,el3 | $("h1,div,p") | All <h1>, <div> and <p> elements |
$("p:first") | The first<p> element | |
$("p:last") | The last<p> element | |
$("tr:even") | All even<tr> elements, the index value starts from 0, the first one The element is even (0), the second element is odd (1), and so on. | |
$("tr:odd") | All odd<tr> elements, the index value starts from 0, the first The first element is even (0), the second element is odd (1), and so on. | |
:first-child | $("p:first-child") | All elements belonging to the first child element of its parent element <p> Element |
:first-of-type | $("p:first-of-type") | belongs to its parent The first <p> element of the element All <p> elements of the element |
:last-child | $("p:last-child") | All<p> elements that are the last child of their parent element |
:last-of-type | $("p: last-of-type") | All<p> elements that belong to the last <p> element of its parent |
n) | $("p:nth-child(2)")All <p> elements that are the second child of their parent element | |
n) | $("p:nth-last-child(2)")All <p> elements that are the second child element of their parent element, counting from the last child element | |
n) | $("p:nth-of-type(2)")All <p> elements that belong to the second <p> element of its parent element | |
n) | $("p:nth-last-of-type(2) ")All <p> elements that are the second <p> element of their parent, counting from the last child element | |
$("p:only-child") | All <p> elements | |
$("p:only-of-type") | All <p> elements that are the only child elements of a specific type from their parent element | |
All <p> elements that are direct children of the<div> element | ##parent descendant | |
<div> All<p> elements that are descendants of the element | element + next | |
The next <p> element adjacent to each <div> element | element ~ siblings | |
<div> All<p> elements at the same level of the element | ||
##:eq( index | )||
The fourth element in the list (index value starts from 0) | :gt( | no | )
List elements with index greater than 3 | :lt( | no | )
List elements with index less than 3 | :not( | selector | )
All input elements that are not empty | ||
:header | $(":header") | All header elements<h1>, <h2> ... |
:animated | $(":animated") | All animated elements |
:focus | $(":focus") | The element that currently has focus |
:contains(text) | $(":contains('Hello')") | All elements containing the text "Hello" |
:has(selector) | $("div:has(p)") | All <div> elements that contain <p> elements inside them |
:empty | $(":empty") | All empty elements |
:parent | $(": parent") | All elements that are the parent of another element |
:hidden | $("p:hidden") | All hidden <p> elements |
:visible | $("table:visible") | All visible tables |
:root | $(":root") | The root element of the document |
:lang (language) | $("p:lang(de)") | All <p> elements with a lang attribute value starting with "de" |
[attribute] | $("[href]") | All elements with href attributes |
[attribute=value ] | $("[href='default.htm']") | All elements with href attribute and value equal to "default.htm" |
[attribute!=value] | $("[href!='default.htm']") | All Elements with href attribute and value not equal to "default.htm" |
[attribute$=value] | $("[href$='.jpg']") | All elements with href attribute and value ending with ".jpg" |
[attribute|=value] | $("[title|='Tomorrow']") | All attributes with title and value equal to' Tomorrow' or a string starting with 'Tomorrow' followed by a connector |
[attribute^=value] | $("[title^='Tom']") | All elements with a title attribute and a value starting with "Tom" |
[ attribute~=value] | $("[title~='hello']") | All attributes with title and the value containing the word "hello" " element |
[attribute*=value] | $("[title*='hello'] ") | All elements with a title attribute whose value contains the string "hello" |
[name=value][name2=value2] | $( "input[id][name$='man']" ) | with Input box with id attribute and name attribute ending with man |
:input | $(":input") | All input elements |
:text | $(":text") | All input elements with type="text" |
:password | $(":password") | All input elements with type="password" |
:radio | $(":radio") | All input elements with type="radio" |
:checkbox | $(":checkbox") | All input elements with type="checkbox" |
:submit | $(":submit") | All input elements with type="submit" |
:reset | $(":reset" ) | All input elements with type="reset" |
:button | $(":button") | All input elements with type="button" |
:image | $(":image") | All with type= Input elements of "image" |
:file | $(":file") | All input elements with type="file" |
:enabled | $(":enabled") | All enabled elements |
: disabled | $(":disabled") | All disabled elements |
:selected | $(":selected" ) | All selected drop-down list elements |
:checked | $(":checked") | All selected The checkbox option |
.selector | $(selector).selector | is deprecated in jQuery 1.7. Return the original selector passed to jQuery() |
:target | $("p:target") | The selector will Selects the <p> element |