Selector Reference

Selector PatternExampleDescription
Element$(‘div’)Selects all <div> elements
:first$(‘div:first’)Selects first <div> element in a DOM hierarchy.
:last$(‘div:last’)Selects last <div> element in a DOM hierarchy.
Multiple elements$(‘p, div, code’)Selects <p>,<div> and <code> elements
parent descendant$(‘div p’)Selects all <p> elements which is descendant of <div>
parent child$(‘div > p’)Selects <p> element which is child of <div>
*$(*)Selects all elements
#Id$(“#myDiv”)Selects element whose id is myDiv
element#id$(“div#myDiv”)Selects <div> element whose Id is myDiv
Multiple Ids$(“#myDiv1, #myDiv2”)Selects multiple elements whose id is myDiv1 or myDiv2.
.class$(“.myCSSClass”)Selects all the elements with class=myCSSClass.
.class .class$(“.myCSSClass1, .myCSSClass2 “)Finds all elements whose class attribute is set to myCSSClass1 or myCSSClass2
element.class$(“div.myCSSClass”)Finds all <div> elements with class=myCSSClass
:first-child$(“p:first-child”)Selects all <p> elements which is the first child of its parent element. (parent element can be anything)
:last-child$(“p:last-child”)Selects all <p> elements which is the last child of its parent element. (parent element can be anything)
:nth-child(n)$(“p:nth-child(5)”)Selects all <p> elements which is the 5th child of its parent element. (parent element can be anything)
:nth-last-child(n)$(“p:nth-last-child(2)”)Selects all <p> elements which is the 2nd last child of its parent element. (parent element can be anything)
:only-child$(“p:only-child”)Selects all <p> elements which is the only child of its parent element. (parent element can be anything)
[attribute]$(‘[class]’)Selects all the elements with the class attribute(whatever the value).
[element[attribute]$(“div[class]”)Selects all the <div> elements that have a class attribute(whatever the value).
element[attribute = value]$(“div[class=’myCls’]”)Selects all the <div> elements whose class attributes are equal to myCls.
element[attribute |= value]$(“div[class|= ‘myCls’]”)Selects all the <div> elements whose class attributes are either equal to myCls or starting with myCls string followed by a hyphen (-).
element[attribute *= “value”]$(“div[class *= ‘myCls’]”)Selects <div> elements whose class attributes contains myCls.
element[attribute ~= “value”]$(“div[class ~= ‘myCls’]”)Selects div elements whose class attributes contains myCls, delimited by spaces.
element[attribute $= “value”]$(“div[class $= ‘myCls’]”)Selects <div> elements whose class attribute value ends with myCls. The comparison is case sensitive.
element[attribute != “value”]$(“div[class != ‘myCls’]”)Selects <div> elements which do not have class attribute or value does not equal to myCls.
element[attribute ^= “value”]$(“div[class ^= ‘myCls’]”)Selects <div> elements whose class attribute value starts with myCls.
:contains(“value”)$(“div:contains(‘tutorialsteacher’)”Selects all <div> elements that contains the text ‘tutorialsteacher’
:input$(“:input”)Selects all input elements.
:button$(“:button”)Selects all input elements where type=”button”.
:radio$(“:radio”)Selects all input types where type=”radio”
:text$(“:text”)Selects all input elements where type=”text” .
“:checkbox”$(“:checkbox”)Selects all checkbox elements.
:submit$(“:submit”)Selects all input elements where type=”submit”.
:password$(“:password”)Selects all input elements where type=”password”.
:reset$(“:reset”)Selects all input elements where type=”reset”.
:image$(‘:image’)Selects all input elements where type=”image”.
:file$(‘:file’)Selects all input elements where type=”file”.
:enabled$(‘:enabled’)Selects all enabled input elements.
:disabled$(‘:disabled’)Selects all disabled input elements.
:selected$(‘:selected’)Selects all selected input elements.
:checked$(‘:checked’)Selects all checked input elements.
:hidden$(‘:hidden’)Selects all hidden elements.
:visible$(‘:visible’)Selects all visible elements.
:odd$(‘tr:odd’)Selects all odd rows. (1,3,5,7..)
:even$(‘tr:even’)Selects all even rows.(0,2,4,6..)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *