Virtual Classes Logo          Virtual Classes
    Read Anytime,Anywhere

Jquery Chaining

Jquery Chaining allows us to run multiple jQuery methods one after the other on the same element within a single statement.
This way, browsers do not have to find the same element(s) more than once.
The chaining increases performance becuase browser doest not have to find the same element again.
To chain an action, you simply append the action to the previous action.

The following example chains together the css(), slideUp(), and slideDown() methods.
The "p1" element first changes to red, then it slides up, and then it slides down:
Example $("#p1").css("color", "red").slideUp(2000).slideDown(2000);

In chaining, the line of code could become quite long.However, jQuery is not very strict on the syntax, you can format it like you want, including line breaks and indentations.
We can write previous example as -
$("#p1").css("color", "red")
.slideUp(2000)
.slideDown(2000);