jquery Chain-action

Source: Internet
Author: User

jquery Chain-action

In jquery, after executing the method, the current object (return this )is returned, and the object can of course continue to invoke the method, so we can do the chaining.

Let's start with an example:

$ ("Li"). CSS ("Color", "gold"). Prevall (). CSS ("Color", "gold");

Call CSS () to a JQuery object to modify the node style, and then use Prevall (). CSS () to modify the style of all sibling nodes before the node, which is called a chain-like operation.

Chained operations can make the code concise, because it is often possible to implement more than one statement in a single statement to accomplish a task.

If you do not use chained operations, you need to use two statements to complete the above tasks:

$ ("Li"). CSS ("Color", "gold");

$ ("Li"). Prevall (). CSS ("Color", "gold");

In addition to increasing the amount of code, also called two times the selector, reducing the speed.

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.