What is method chaining in jQuery?

With jQuery, we can chain multiple methods on an element. We do not need to select the same element multiple times to implement a method on it. Rather, we can just add the methods together into one single line of code.

Syntax

$(element).action1().action2()...

Code

In the example below, when you click the button, the paragraph element, which has the id test, has methods called on it one after the other using method chaining.

First, we change the text color and then slide the paragraph element up and down.

Free Resources