Summary of commonly used element search methods of jquery

Source: Internet
Author: User

 

$ ("# 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 an array of DIV elements.
$ (". Myclass") select all elements of CSS using the myclass class
$ ("*") Select all the elements in the document and use multiple options for joint selection: for example, $ ("# myelement, Div,. myclass ")

Cascade selector:
$ ("Form input") 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 Label is directly followed by all input tag elements of an input tag.

$ ("# Prev ~ Div ") compatriot selector, which returns all Div tags of the Tag Element with ID as Prev that belongs to the same parent element.

Basic filter selector:
$ ("TR: First") Select the first element of all tr
$ ("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 ...... (Note: Because the selected multiple elements are arrays, the serial number starts from 0)

$ ("TR: odd") select elements 1, 3, 5... 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 whose Div contains John text.
$ ("TD: empty") Select an array of all TD elements that are empty (or contain 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 to be 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 the input element 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 'new '.

$ ("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:

$ ("Ul Li: Nth-child (2)"), $ ("Ul Li: Nth-child (ODD)"), $ ("Ul Li: nth-child (3N + 1 )")

$ ("Div span: First-Child") returns the array of the first subnode of all DIV elements.
$ ("Div span: Last-Child") returns the array of the last node of all DIV elements.
$ ("Div button: 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.

 

SelectNameIt is the text value of the previous TD in the input text box of "s_03_22 ".
$ ("Input [@Name= S_03_22] "). Parent (). Prev (). Text ()

The name starts with "S _" and does not end with "_ r"
$ ("Input [@Name^ ='S _ '] "). Not ("[@Name$ = '_ R'] ")

The value of a radio_01 radio.
$ ("Input [@Name= Radio_01] [@ checked] "). Val ();

 

 

$ ("A B") searches for all subnodes under Element A, including non-direct subnodes.
$ ("A> B") Find the direct subnode under Element
$ ("A + B") searches for the sibling nodes behind Element A, including non-direct subnodes.
$ ("~ B ") Find the sibling nodes behind Element A, excluding non-direct subnodes.

1. $ ("a B") searches for all subnodes under Element A, including non-direct subnodes.

Example: Find all input elements in the form

HTML code:

<Form>
<Label> name: </label>
<Input name = "name"/>
<Fieldset>
<Label> Newsletter: </label>
<Input name = "newsletter"/>
</Fieldset>
</Form>
<Input name = "NONE"/>
Jquery code:

$ ("Form input ")
Result:

[<Input name = "name"/>, <input name = "newsletter"/>]

2. $ ("A> B") Find the direct subnode under Element
Example: match all the child input elements in the form.

HTML code:

<Form>
<Label> name: </label>
<Input name = "name"/>
<Fieldset>
<Label> Newsletter: </label>
<Input name = "newsletter"/>
</Fieldset>
</Form>
<Input name = "NONE"/>
Jquery code:

$ ("Form> input ")
Result:

[<Input name = "name"/>]

3. $ ("A + B") searches for the sibling nodes behind Element A, including non-direct subnodes.
Example: match all input elements following the label

HTML code:

<Form>
<Label> name: </label>
<Input name = "name"/>
<Fieldset>
<Label> Newsletter: </label>
<Input name = "newsletter"/>
</Fieldset>
</Form>
<Input name = "NONE"/>
Jquery code:

$ ("Label + input ")
Result:

[<Input name = "name"/>, <input name = "newsletter"/>]

4. $ ("~ B ") Find the sibling nodes behind Element A, excluding non-direct subnodes.
Example: Find all input elements of the same generation as the form

HTML code:

<Form>
<Label> name: </label>
<Input name = "name"/>
<Fieldset>
<Label> Newsletter: </label>
<Input name = "newsletter"/>
</Fieldset>
</Form>
<Input name = "NONE"/>
Jquery code:

$ ("Form ~ Input ")
Result:

[<Input name = "NONE"/>]

$ ("# 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 an array of DIV elements.
$ (". Myclass") select all elements of CSS using the myclass class
$ ("*") Select all the elements in the document and use multiple options for joint selection: for example, $ ("# myelement, Div,. myclass ")

Cascade selector:
$ ("Form input") 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 Label is directly followed by all input tag elements of an input tag.

$ ("# Prev ~ Div ") compatriot selector, which returns all Div tags of the Tag Element with ID as Prev that belongs to the same parent element.

Basic filter selector:
$ ("TR: First") Select the first element of all tr
$ ("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 ...... (Note: Because the selected multiple elements are arrays, the serial number starts from 0)

$ ("TR: odd") select elements 1, 3, 5... 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 whose Div contains John text.
$ ("TD: empty") Select an array of all TD elements that are empty (or contain 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 to be 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 the input element 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 'new '.

$ ("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:

$ ("Ul Li: Nth-child (2)"), $ ("Ul Li: Nth-child (ODD)"), $ ("Ul Li: nth-child (3N + 1 )")

$ ("Div span: First-Child") returns the array of the first subnode of all DIV elements.
$ ("Div span: Last-Child") returns the array of the last node of all DIV elements.
$ ("Div button: 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.

 

SelectNameIt is the text value of the previous TD in the input text box of "s_03_22 ".
$ ("Input [@Name= S_03_22] "). Parent (). Prev (). Text ()

The name starts with "S _" and does not end with "_ r"
$ ("Input [@Name^ ='S _ '] "). Not ("[@Name$ = '_ R'] ")

The value of a radio_01 radio.
$ ("Input [@Name= Radio_01] [@ checked] "). Val ();

 

 

$ ("A B") searches for all subnodes under Element A, including non-direct subnodes.
$ ("A> B") Find the direct subnode under Element
$ ("A + B") searches for the sibling nodes behind Element A, including non-direct subnodes.
$ ("~ B ") Find the sibling nodes behind Element A, excluding non-direct subnodes.

1. $ ("a B") searches for all subnodes under Element A, including non-direct subnodes.

Example: Find all input elements in the form

HTML code:

<Form>
<Label> name: </label>
<Input name = "name"/>
<Fieldset>
<Label> Newsletter: </label>
<Input name = "newsletter"/>
</Fieldset>
</Form>
<Input name = "NONE"/>
Jquery code:

$ ("Form input ")
Result:

[<Input name = "name"/>, <input name = "newsletter"/>]

2. $ ("A> B") Find the direct subnode under Element
Example: match all the child input elements in the form.

HTML code:

<Form>
<Label> name: </label>
<Input name = "name"/>
<Fieldset>
<Label> Newsletter: </label>
<Input name = "newsletter"/>
</Fieldset>
</Form>
<Input name = "NONE"/>
Jquery code:

$ ("Form> input ")
Result:

[<Input name = "name"/>]

3. $ ("A + B") searches for the sibling nodes behind Element A, including non-direct subnodes.
Example: match all input elements following the label

HTML code:

<Form>
<Label> name: </label>
<Input name = "name"/>
<Fieldset>
<Label> Newsletter: </label>
<Input name = "newsletter"/>
</Fieldset>
</Form>
<Input name = "NONE"/>
Jquery code:

$ ("Label + input ")
Result:

[<Input name = "name"/>, <input name = "newsletter"/>]

4. $ ("~ B ") Find the sibling nodes behind Element A, excluding non-direct subnodes.
Example: Find all input elements of the same generation as the form

HTML code:

<Form>
<Label> name: </label>
<Input name = "name"/>
<Fieldset>
<Label> Newsletter: </label>
<Input name = "newsletter"/>
</Fieldset>
</Form>
<Input name = "NONE"/>
Jquery code:

$ ("Form ~ Input ")
Result:

[<Input name = "NONE"/>]

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.