Chaining is the ways to chain the method one after other method in the single function.
It is one of very important concepts in Jquery. Using chaining, we can write multiple Jquery methods with in the single statement.
Note: Most Jquery methods are chainable but not all.
Now let see one of the basic example of chaining in Jquery
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="../../Scripts/jquery.min.js"></script> <script> $(function () { $("#Chain").click(function () { $("p").css({ "background-color": "green", "height": "300px", "width": "300px" }) .slideUp(3000).slideDown(3000) .animate({ left: '350px' }, 5000) .animate({ top: '350px' }, 5000) .animate({ left: 0 }, 5000) .animate({ top: 0 }, 5000); }); }); </script> </head> <body> <button id="Chain">Click here</button> <br /> <p style="position:absolute;"> Try to animate me. </p> </body> </html>
Summary
In the above example we showed that the basic example chaining in Jquery.
One thought on “what is the chaining in Jquery ?(Part 6)”