About JQuery Selector

Source: Internet
Author: User

About JQuery Selector

In front-end operations, in many cases, we need to filter different page objects according to certain business needs, for example, to select all checkpoints, for example, to select input, there are even more responsible screening. At this time, jQuery's selector can be a good helper for us. jQuery's selector is very powerful. Here we will briefly summarize the commonly used element search methods.

 

$ (# MyELement) Select the element whose id value is equal to myElement. The id value cannot be repeated. Only one id value in the document is myElement, so the result is a unique element.

$ (Div) Select All div tag elements and return the div element array.

$ (. MyClass) select all elements of css using myClass class

$ (*) Select all the elements in the document and use multiple options for joint selection: for example, $ (# myELement, div,. myclass)

 

Cascade selector:

$ (Forminput) Select the input element from all form elements

$ (# Main> *) select all child elements whose id is main.

$ (Label + input) Select the next input element node of all label elements. The result returned by the test selector is that the label is directly followed by all input tag elements of an input tag.

$ (# Prev ~ Div) compatriot selector, which returns all the div tags of the Tag Element with id as prev that belong to the same parent element.

 

Basic filter selector:

$ (Tr: first) Select the first element of all tr Elements

$ (Tr: last) Select the last one of all tr Elements

$ (Input: not (: checked) + span)

 

Filter out all input elements of the checked selector.

 

$ (Tr: even) Select the 0, 2, 4 ...... of all tr elements ...... (Note: Because the selected multiple elements are arrays, the serial number starts from 0)

 

$ (Tr: odd) Select the 1, 3, 5 ...... elements of all tr elements.

$ (Td: eq (2) Select the td element whose Sn is 2 from all td elements.

$ (Td: gt (4) Select All td elements whose serial number is greater than 4 in the td Element

$ (Td: ll (4) Select All td elements whose serial number is less than 4 in the td Element

$ (: Header)

$ (Div: animated)

Content Filter selector:

 

$ (Div: contains ('john') select all elements containing the John text in the div

$ (Td: empty) Select an array of all td elements that are empty (and do not include text nodes)

$ (Div: has (p) Select All div elements containing the p tag

$ (Td: parent) Select All element arrays with td as the parent node

Visual filter selector:

 

$ (Div: hidden) select all the div elements hidden

$ (Div: visible) Select All visualized div elements

Attribute filter selector:

 

$ (Div [id]) 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 the input element whose name attribute is not equal to 'newsletter '.

 

$ (Input [name ^ = 'News']) select all input elements whose name attributes start with 'News '.

$ (Input [name $ = 'News']) select all input elements whose name attributes end with 'News '.

$ (Input [name * = 'man']) select all input elements whose name attribute contains 'News '.

 

$ (Input [id] [name $ = 'man ']) multiple attributes can be used for joint selection, this selector is used to obtain all elements that contain the id attribute and end with man.

 

Child element filter selector:

 

$ (Ulli: nth-child (2), $ (ul li: nth-child (odd), $ (ulli: nth-child (3n + 1 ))

 

$ (Divspan: first-child) returns the array of the first subnode of all div elements

$ (Divspan: last-child) returns the array of the last node of all div elements

$ (Divbutton: only-child) returns an array of all child nodes with only one subnode 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) select all the checkbox input Elements

$ (: Submit) select all submit input Elements

$ (: Image) select all image input Elements

$ (: Reset) select all reset input Elements

$ (: Button) select all button input Elements

$ (: File) select all file input Elements

$ (: Hidden) Select the hidden fields of all input elements or forms of the hidden type.

 

Form element filter selector:

 

$ (: Enabled) Select All operable form elements

$ (: Disabled) Select All unoperable form elements

$ (: Checked) select all checked form elements

$ (Select option: selected) select the selected element from all select sub-elements.

 

 

 

Now, I feel more and more that the front-end js is powerful. No matter what function, you can't think of it. The strength of js is not just as simple as the functions you just understood at the beginning, the more I use it, the more I admire it.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.