Jquery Chaining

jQuery - Chaining


With jQuery, yous tin flame chain together actions/methods.
Chaining allows us to run multiple jQuery methods (on the same element) inside a unmarried statement.

jQuery Method Chaining

Until directly nosotros convey been writing jQuery statements ane at a fourth dimension (one afterwards the other).
However, at that spot is a technique called chaining, that allows us to run multiple jQuery commands, ane afterwards the other, on the same element(s).
Tip: This way, browsers create non convey to notice the same element(s) to a greater extent than than once.
To chain an action, yous precisely append the activeness to the previous action.
The next instance chains together the css(), slideUp(), too slideDown() methods. The "p1" chemical component subdivision offset changes to red, too thence it slides up, too and thence it slides down:

Example

$("#p1").css("color", "red").slideUp(2000).slideDown(2000);
We could likewise convey added to a greater extent than method calls if needed.
Tip: When chaining, the business of code could decease quite long. However, jQuery is non really strict on the syntax; yous tin flame format it similar yous want, including business breaks too indentations.
This likewise plant precisely fine:

Example

$("#p1").css("color", "red")
  .slideUp(2000)
  .slideDown(2000);
jQuery throws away extra whitespace too executes the lines higher upwards every bit ane long business of code.


Comments

Popular posts from this blog

What Are The Main Components of a Computer System

Top Qualities To Look For In An IT Support Team

How To Integrate Google Adwords Api Into Codeigniter?