A common summary of jQuery selectors

  • 2020-03-30 04:24:04
  • OfStack

Basic element selector


$("p")
$("p.ii") Select all class=ii the p The element
$("p#demo") select id=demo One of the first p The element

Layer selector


$("div input")div Of all the input
$("div>input")

Basic condition selector


$("p:first")
$("p:last")
$("tr:even") Select even rows
$("tr:odd") An odd number
$("input:not(:checked)") Select all elements selected for this
$("tr:eq(1)") Index values for 1 The table of
$("tr:gt(0)") Is greater than 0
$("tr:lt(0)") Less than 0
$(":header") Select all title elements
$(":animated") Animation being executed

Content condition selector


$("div:constains('ddd')") Choose to include ddd Layer elements of text
$("td:empty") Select a table cell that contains no text or child elements
$("div:has(p)") Select the layer element that contains the paragraph element
$("td:parent") Select the table cell that contains child elements or text

Visibility condition selector


$("tr:hidden")  //Select all hidden tables
$("tr:visible") Select all visible tables

Attribute selector


$("div[id]") with id Properties of the layer
$("input[name='']") input attribute name=''
$("input[name!='']")
$("input[name^='']") Choose to have name Property and the value is' ' Enter the element for the form that starts with the content
$("input[name$='']") Choose to have name Property and the value is' ' Enter an element for the form that ends the content
$("input[name*='']") Choose to have name Property and the value is' ' Form input elements
$("input[id][name$='']") Choose to have id and name The value of the property begins with ' ' Enter the form element to end the content

Child element selector


$("ul li:nth-child(2)") Select the second list item
$("ul li:nth-child(even)")
$("ul li:nth-child(odd)")
$("ul li:nth-child(3n)")
$("ul li:first-child")
$("ul li:last-child")
$("ul li:only-child") Select list appears and only one list item appears

Form element selector


$("input") Select all the input textarea select button Elements such as
$(":text") Text lines
$(":password")
$(":radio")
$(":checkbox")
$(":submit")
$(":image")
$(":reset")
$(":button")
$(":file")
$(":hidden")

Form property selector


$("input:enabled")  //Select all available
$("input:disabled")
$("input:checked")
$("select:option:selected")


Related articles: