Saturday, 26 March 2016

How to do Method chaining in jQuery ?


jQuery Method chaining

Chaining allows us to run multiple jQuery methods (on the same element) within a single statement.
To chain an action, you simply append the action to the previous action.

Example
$("#p1").css("color","red").slideUp(2000).slideDown(2000);

Format the code so that the line of code could not become quite long.
Example
$("#p1").css("color","red")
  .slideUp(2000)
  .slideDown(2000);

No comments:

Post a Comment

Note: only a member of this blog may post a comment.