JQuery Various selection Method code summary

Source: Internet
Author: User
Tags prev


1, find all the elements meet the conditions found ()
Example: $ (' ul '). Find (' Li '). addclass (' tmpexample ');
Find all LI elements under the UL element in the page and add a tmpexample style to the found Li element.

2. Find the sibling node of the specified element siblings ()
Example: $ (' Li#tmpcarrot '). Slblings (). addclass (' tmpexample ');
Finds all sibling nodes of the LI element with ID Tmpcarrot and adds a tmpexample style to the sibling node that is found.
You can add a selector to the slblings () bracket to find the sibling node for the specified condition. such as: Slblings ('. Tmpclass '), is to find the class

The sibling node for Tmpclass.

3, find the next sibling node of the specified node next ()
Example: $ (' Li#tmpbroccoli '). Next (). addclass (' tmpexample ');
Look for the next sibling of the Li node with ID tmpbroccoli. And adds a tmpexample style to the sibling node you find.

4. Find all sibling nodes next () after the specified node
Example: $ (' Li#tmpbroccoli '). Nextall (). addclass (' tmpexample ');
Finds all sibling nodes behind the LI node with ID tmpbroccoli. And adds a tmpexample style to the sibling node you find.

5. Find the previous sibling node of the specified node prev ()
Example: $ (' Li#tmpbroccoli '). Prev (). addclass (' tmpexample ');
Finds the previous sibling node of the LI node with ID tmpbroccoli. And adds a tmpexample style to the sibling node you find.

6. Find all the sibling nodes in front of the specified node Prevall ()
Example: $ (' Li#tmpbroccoli '). Prevall (). addclass (' tmpexample ');
Look for all the sibling nodes in front of the Li node with ID tmpbroccoli. And adds a tmpexample style to the sibling node you find.
You can add a selector to the Prevall () bracket to find the sibling node for the specified condition. such as: Prevall (' Li.tmpclass '), is to find when

All classes in front of the front node are tmclass sibling nodes.

7, to find all eligible for the Superior node parents ()
Example: $ (' Li#tmpcarrot '). Parents (' div#tmps tutorial election '). addclass (' tmpexample ');
Find all the div ancestor nodes with id tmpcarrot of the LI node with IDs Tmpselection. and add a tmpexample sample to the found node

Expression

8, find the parent node parent ()
Example: $ (' Li#tmpcarrot '). Parent (). addclass (' tmpexample ');
Finds the ancestor node of the LI node with ID tmpcarrot. And adds a tmpexample style to the found node.

9, Lookup child node children ()
Example: $ (' div.tmplist '). Children (' H4 '). addclass (' tmpexample ');
Look for H4 tags in the child nodes below the div with class tmplist. And adds a tmpexample style to the found node.

10. Select Not () in the set of nodes found
Example: $ (' ul Li '). Not (' Li.tmpvegetables '). addclass (' tmpexample ');
In the found Li Collection, add a tmpexample style in addition to the class-Tmpvegetables node.

11. Select the fragment slice in the node collection ()
Example: $ (' ul Li '). Slice (1,4). addclass (' tmpexample ');
Found in the Li Collection, select from the 1th (counting from 0, the first is actually the second) node to start, backwards 4 nodes, and for these 4

Node adds tmpexample style.

12. Add nodes to the result set of the lookup add ()
Example: $ (' Ul#tmpanimals Li '). Add (' Li#tmpbrocoli,li#tmppepper '). addclass (' tmpexample ');
An Li node set under the UL node with ID tmpanimals, an LI node with ID tmpbrocoli and an Li node with an ID of Tmppepper added. And

Adds the tmpexample style to all LI nodes in the grouped collection.

13, the result set select the specified element eq ()
Example: $ (' ul Li '). Eq. addclass (' tmpexample ');
Page ul below the Li Collection, adds the Tmpexample style to the 10th element

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.