Home  >  Article  >  Web Front-end  >  jquery selector (common selector description)_jquery

jquery selector (common selector description)_jquery

WBOY
WBOYOriginal
2016-05-16 18:19:111106browse
Basic selector:

$("#myELement") Select the element whose id value is equal to myElement. The id value cannot be repeated. There can only be one id value myElement in the document, so what you get is The only element

$("div")                                                                                                                  ,                                       out out out  through           through  -             off out of div tag element is returned. >
$("*") Select all elements in the document

You can use a variety of selection methods for joint selection: For example, $("#myELement,div,.myclass")


Cascading selector:

$("form input") Select all input elements in form elements
$("#main > *") Select all child elements with the id value of main

$("label input") Select the next input element node of all label elements

After testing, the selector returns the label after the label All input tag elements directly followed by an input tag

$("#prev ~ div") Sibling selector

This selector returns all the tag elements whose id is prev. DIV tags of the same parent element


Basic filtering selector:

$ ("tr: first") Select the first


🎜>$("tr:last")                                                                                                                                                                              Select the last of all tr ​​elements

$("input:not(:checked) span")                               All input elements

$("tr:even") Select the 0th, 2nd, 4th... elements of all tr ​​elements (note: because when multiple elements are selected, Array, so the sequence number starts from 0)

$("tr:odd")                                                                                                                                                                                                                                        can select the 1st, 3rd, 5th... ... elements of all tr ​​elements

$ ("TD: EQ (2)") Select the TD element with a serial number 2 in all TD elements

$ ("td: gt (4)") Select all TDs with a sequence number in the TD element greater than 4 Element $ ("td: ll (4)") Select all TD elements with a serial number in the TD element less than 4

$ (": header")

$ ("div:animated")


Content filter selector:


$("div:contains('John')") Select all divs that contain John text Elements
$("td:empty") Select all empty (not including text nodes) td element array
$("div:has(p)") Select all div elements containing p tags

$("td:parent") Select all element arrays with td as the parent node


Visual filter selector:


$("div:hidden") Select all hidden div elements
$("div:visible") Select all visible div elements

Attribute filter selector:


$("div") Select all div elements containing the id attribute
$("input[name='newsletter']") Select All input elements whose name attribute is equal to 'newsletter'
$("input[name!='newsletter']") Select all input elements whose name attribute is not equal to 'newsletter'

$("input[name^='news']") Select all input elements whose name attribute starts with 'news'

$("input[name$='news']") Select all Input elements whose name attribute ends with 'news'

$("input[name*='man']") Select all input elements whose name attribute contains 'news'

$( "input[name$='man']") You can use multiple attributes for joint selection. This selector gets all the


child elements that contain the id attribute and the attribute ends with man. Filter selector:


$("ul li:nth-child(2)"),$("ul li:nth-child(odd)"),$("ul li:nth-child(3n 1)" )

$("div span:first-child") Returns an array of the first child nodes of all div elements

$("div span:last-child") Returns all The array of the last node of the div element

$("div button:only-child") Returns the array of all child nodes that have only one child node in all divs

Form element selector:

$(":input") Select all form input elements, including input, textarea, select and button

$(":text") Select all text input elements

$(":password") Select all password input elements

$(":radio") Select all radio input elements

$(":checkbox")                                                                                           can select all checkbox input elements

$ (":submit")                                                         can be selected in all. Elements

$(":reset") Select all reset input elements

$(":button") Select all button input elements

$(":file ") Choose all File input elements

$ (":: hidden ") Select all types of INPUT elements or forms of hidden or forms of the hidden domain


Form unit element filter selection:
$(":enabled")                                                                                       can select all operable form elements                                                                                                 can select all the form elements that are not operable
$(":disabled")                     $(":checked") Select all checked form elements

$("select option:selected") Select all selected elements in the child elements of select
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn