JQuery selection and filtering method code Summary

Source: Internet
Author: User

1. find all matching elements ()
Example: $ ('ul '). find ('lil'). addClass ('tmpexample ');
Search for all the li elements under the ul element on the page, and add the tmpExample style to the searched li element.

2. Find the sibling node siblings () of the specified element ()
Example: $ ('Li # tmpcarrot'). slblings (). addClass ('tmpexample ');
Find all the sibling nodes of the li element whose ID is tmpCarrot, and add the tmpExample style to the sibling node.
You can add a selector to the slblings () brackets to find the sibling node with the specified condition. For example, slblings ('. tmpClass') is a query class.

It is the sibling node of tmpClass.

3. Search for the next sibling node next () of the specified Node ()
Example: $ ('Li # tmpbroccol'). next (). addClass ('tmpexample ');
Find the next sibling node of the li node with the ID tmpBroccoli. Add the tmpExample style to the brothers found.

4. Search for all the sibling nodes next () after a specified Node ()
Example: $ ('Li # tmpbroccol'). nextAll (). addClass ('tmpexample ');
Find all the sibling nodes after the li node with the ID tmpBroccoli. Add the tmpExample style to the brothers found.

5. Search for the previous sibling node prev () of the specified Node ()
Example: $ ('Li # tmpbroccol'). prev (). addClass ('tmpexample ');
Find the previous sibling node of the li node with the ID tmpBroccoli. Add the tmpExample style to the brothers found.

6. Search for the prevAll ()
Example: $ ('Li # tmpbroccol'). prevAll (). addClass ('tmpexample ');
Find all the preceding sibling nodes of the li node with the ID tmpBroccoli. Add the tmpExample style to the brothers found.
You can add a selector in the brackets of prevAll () to find the sibling node with the specified condition. For example, prevAll ('Li. tmpClass ') is to find

All the sibling nodes whose classes are tmClass before the front node.

7. Search for all qualified parent node parents ()
Example: $ ('Li # tmpcarrot'). parents ('div # tmpSelection '). addClass ('tmpexample ');
Find all the parent div nodes whose IDs are tmpSelection of the li node whose IDs are tmpCarrot. Add the tmpExample sample for the searched node.

.

8. Search for the parent node parent ()
Example: $ ('Li # tmpcarrot'). parent (). addClass ('tmpexample ');
Find the upper-level node of the li node whose ID is tmpCarrot. Add the tmpExample style to the node to be searched.

9. Find the child node children ()
Example: $ ('div. tmplist'). children ('h4 '). addClass ('tmpexample ');
Find the h4 tag in the subnode under the div whose class is tmplist. Add the tmpExample style to the node to be searched.

10. Select not () from the searched node set ()
Example: $ ('ul li '). not ('Li. tmpVegetables'). addClass ('tmpexample ');
In the found li collection, a tmpExample style is added except for the node whose class is tmpVegetables.

11. Select slice () in the node set ()
Example: $ ('ul li '). slice (). addClass ('tmpexample ');
In the found li set, select the first 1st (counting from 0, the first is actually the second) nodes, and the last four nodes for the four

Add the tmpExample style to the node.

12. add node add () to the search result set ()
Example: $ ('ul # tmpAnimals li '). add ('Li # tmpBrocoli, li # tmpPepper'). addClass ('tmpexample ');
The li node set under the ul node whose id is tmpAnimals. Add the li node whose id is tmpBrocoli and the li node whose id is tmpPepper. And

Add the tmpExample style to all the li nodes in the combined set.

13. Select the specified Element eq () in the result set ()
Example: $ ('ul li '). eq (10). addClass ('tmpexample ');
Add the tmpExample style to the 10th element in the li collection under ul on the page.

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.