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

Do we need to add jQuery file in both Master and Content page?

467


What does dollar sign ($) means in jquery? : jquery mobile

432


How can jquery library be added to pages? Write a basic jquery code?

470


Explain .on()? : jquery mobile

484


What is .remove()? : jquery mobile

463






How we can hide a block of html code on a button click using jquery?

481


List a few features of jquery mobile? : jQuery Mobile

403


What is .detach()? : jquery mobile

517


What is jquery datepicker in jquery?

457


Whether jQuery HTML work for both HTML and XML documents?

486


What is the need for jquery? : jQuery Mobile

494


Why should I use jquery?

450


List the advantage of using minimized version of jquery?

424


What does jQuery data() function do?

529


How to include jquery library in asp.net project?

433