Home >Web Front-end >JS Tutorial >Examples of jQuery chain usage in jQuery applications_jquery
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:
The above code adds style css1 to the entire
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.
Hello,howare 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. First paragraph Second paragraph The above jQuery code first searches for the tag in tag, and then uses the andSelf() method to separate Combine them together, and then add style css2. This style is valid for both . Effect: First paragraph Second paragraph I hope this article will be helpful to everyone’s jQuery programming.
Related articles
See more