HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
With jQuery, you can chain together actions/methods.Chaining allows us to run multiple jQuery methods (on the same element) within a single statement
Until now we have been writing jQuery statements one at a time (one after the other).
However, there is a technique called chaining, that allows us to run multiple jQuery commands, one after the other, on the same element(s).
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:
$("#p1").css("color", "red").slideUp(2000).slideDown(2000);
We could also have added more method calls if needed.
This also works just fine:
$("#p1").css("color", "red")
.slideUp(2000)
.slideDown(2000);
jQuery throws away extra whitespace and executes the lines above as one long line of code.