jQuery selector


jQuery Selectors


jQuery Selectors

Please use our jQuery Selector Detector to demonstrate different selectors.

##:first$("p:first") The first<p> element:last$("p:last")The last<p> element:even$("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. :odd$("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. ##:nth-child($("p:nth-child(2)")All <p> elements that are the second child of their parent element:nth-last-child($("p:nth-last-child(2)")All <p> elements that are the second child element of their parent element, counting from the last child element:nth-of-type($("p:nth-of-type(2)")All <p> elements that belong to the second <p> element of its parent element :nth-last-of-type($("p:nth-last-of-type(2) ")All <p> elements that are the second <p> element of their parent, counting from the last child element:only -child$("p:only-child")All <p> elements## that are the only child elements of their parent element #:only-of-typeparent > child$("div > p")All <p> elements that are direct children of the<div> element$("div p")$("div + p")$("div ~ p"))$("ul li :eq(3)"):gt() $("ul li:gt(3)"):lt()$("ul li:lt(3)"):not()$("input:not(:empty)")
SelectorInstanceSelect
*$(" *")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





: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)
n)
n)
n)
$("p:only-of-type")All <p> elements that are the only child elements of a specific type from their parent element



##parent descendant
<div> All<p> elements that are descendants of the elementelement + next
The next <p> element adjacent to each <div> elementelement ~ 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)no
List elements with index greater than 3no
List elements with index less than 3selector
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

# whose ID matches a formatted identifier in the URI