JQuery Method for searching peer elements _ jquery

Source: Internet
Author: User
This article mainly introduces jQuery's method for searching peer elements. examples show how to use methods such as next, nextAll, nextUtil, prev, and prevAll, A complete example is provided, which has some reference value. If you need it, you can refer to the example below to describe jQuery's method of searching peer elements. Share it with you for your reference. The specific analysis is as follows:

1. next () method

Used to search for a single peer element that follows each matching element. You can also specify a selector to filter peer elements as needed. The syntax format is as follows:

The Code is as follows:

Next ([selector])
$ ("P"). next ("p" ).css ("color", "# FCF ");

2. nextAll () method

Used to search for all peer elements that follow each matching element. You can also specify a selector to filter peer elements as needed.

The Code is as follows:

NextAll ([selector])
$ ("P" ).nextAll().css ("color", "blue ");

3. nextUtil () method

Used to obtain the peer element that follows each matching element until it matches the element of the given selector (but does not include this element). The format is as follows:

The Code is as follows:

NextUtil ([selector])

Instance:

The Code is as follows:

$ ("# P1"). nextUtil ("p" ).css ("border", "1px solid red ");

Set the border of all the intermediate peer elements whose id is p1 to red when the next p element ends.

4. prev () method

Used to search for a single peer element next to each matching element. You can also specify a selector to filter peer elements as needed. The syntax format is as follows:

The Code is as follows:

Prev ([selector])

Instance:

The Code is as follows:

$ ("# P2"). prev ("span" ).css ("color", "blue ");

The font of the span element next to the p2 element changes to blue.

5. prevAll () method

This interface is used to search all peer elements before the current element. You can also specify a selector to filter peer elements. The syntax format is as follows:

The Code is as follows:

PrevAll ([selector])

6. prevUtil () method

It is used to search all peer elements before the current element until the matching element is met. The syntax format is as follows:

The Code is as follows:

PrevUtil ([selector])
$ ("# P2"). prevUtil ("input" ).css ("color", "red ");

7. siblings () method

It is used to search for all peer elements of each matching element. You can also specify a selector to filter these peer elements as needed. The format is as follows:

The Code is as follows:

Siblings ([selector])
$ ("P" ).siblings().css ("color", "red ");

Example:

The Code is as follows:





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.