What is chaining?

In this blog, I will show you What is chaining in jQuery.

With jQuery, you can chain actions/methods together.

Chaining allows us to run multiple jQuery methods (on the same element) within a single statement.

Chaining in jQuery lets you run multiple statements on the same element one after the other. To chain multiple commands, append each jQuery command to the previous one using a dot (.). Chaining allows you to not use a selector more than once to perform an action because all the actions are performed simultaneously. This speeds up the time it takes to execute the code because the compiler does not need to call a selector more than once.

The following example combines the css(), slideUp(), and slideDown() methods together. The “h1” element first turns red, then it slides up, and then slides down:

For Example:

<!DOCTYPE html>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
	   $("#h1").css("color", "blue").slideUp(200).slideDown(100); 
	<p id="h1">what is chaining in jQuery?</p>
	<button>Click me</button>


In the above statement, the color, slideup, and slidedown action are applied on the heading selector in the same line using chaining.

Hope this blog is helpful for you ,Thanks for reading this blog.


What is chaining in jQuery?

How to get the current URL of Laravel in controller and view?