What is chaining in jQuery?

Answer Posted / chaitanya

Chaining is one of the most powerful feature of jQuery. In jQuery, Chaining means to connect multiple functions, events on selectors. It makes your code short and easy to manage and it gives better performance. The chain starts from left to right. So left most will be called first and so on.

Hide Copy Code

​$(document).ready(function(){

$('#dvContent').addClass('dummy');

$('#dvContent').css('color', 'red');

$('#dvContent').fadeIn('slow');

});​

The above jQuery code sample can be re-written using chaining. See below.

Hide Copy Code

​$(document).ready(function(){

$('#dvContent').addClass('dummy')

.css('color', 'red')

.fadeIn('slow');

});​

Not only functions or methods, chaining also works with events in jQuery. Find out more here.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we select a element having a specific class in jquery ?

658


How to use transition effects? : jQuery Mobile

611


Define the script build up by jquery?

678


Explain the difference between .empty() and .remove() ?

593


How do you select all elements with the class of “selected” in jquery?

604


How to divide a page into parts using jquery mobile? : jquery mobile

647


Define jquery filter?

651


Why jquery?

668


What are some of the ways to provide effects? : jQuery Mobile

600


What to do to select element having a particular class (".selected")? : jquery mobile

636


Which program is useful for testing jQuery?

645


How can I select 20th div with jquery?

633


How did you become the creator of jquery ui? Whats the story behind that?

956


Is jquery code exicuted on the clientside, or serverside?

585


What is get()? : jquery mobile

629