Latest web development tutorials

jQuery Chaining

By jQuery, can the action / method linked together.

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

jQuery method chaining

Until now, we were once wrote a jQuery statement (followed by another one).

However, there is a technique called link (chaining), allowing us to run multiple jQuery commands on the same element, and then another one.

Tip: In this case, the browser will not have to repeatedly find the same elements.

To link an action that you should simply appended to the action before the action.

The following example css (), slideUp () and slideDown () linked together. "P1" element will first turn red, then slide up and slide down again:



try it"

If required, we can also add multiple method calls.

Tip: When the link line will become poor.However, jQuery syntax is not very strict; you can follow the desired format for writing, including line breaks and indentation.

You can also write as well run:



try it"

jQuery will throw away the extra space, and as a president of code to perform the above line of code.