Home > Web Front-end > JS Tutorial > body text

Examples of jQuery chain usage in jQuery applications_jquery

WBOY
Release: 2016-05-16 16:19:24
Original
935 people have browsed it

The example in this article describes the usage of jQuery chain in jQuery application. Share it with everyone for your reference. The specific analysis is as follows:

Many times we can link jQuery statements together, which not only shortens the code length, but also often achieves special effects. First look at the following code:

Copy code The code is as follows:

The above code adds style css1 to the entire

list, then filters it, and then adds css2 style individually to the filtered elements. Without jQuery, it would be very troublesome to achieve the above effects.

In the jQuery chain, subsequent operations take the result of the previous operation as the object. If you want the operation object to be the object of the previous step, you can use the end() method.

Use the end() method to control the jQuery chain.

Copy code The code is as follows:

Hello,howare you?


very nice,Thank you.

The above code searches for the tag in

, then adds style css1, uses the end() method to set the operation object back to $("p") and adds style style css2.

In addition, you can also combine the previous two objects through andSelf() and process them together.

Use the andSelf() method to control the jQuery chain.

Copy code The code is as follows:


First paragraph


Second paragraph


The above jQuery code first searches for the

tag in

, adds css1. This style is only valid for the

tag, and then uses the andSelf() method to separate

and

Combine them together, and then add style css2. This style is valid for both

and

.

Effect:

Copy code The code is as follows:

First paragraph


Second paragraph


I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!