What is chaining in jQuery?



What is chaining in jQuery?..

Answer / 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

More jQuery Interview Questions

Tell me can we have multiple document.ready() function on the same page? : jquery mobile

0 Answers  


Is it possible to use jquery to make ajax request? : jquery mobile

0 Answers  


How to create clone of any object using jQuery?

1 Answers  


How can you get the type of arguments passed to a function?

0 Answers  


What are the advantages of method chaining in jquery?

0 Answers  






What is the use of delegate() method in jquery?

0 Answers  


Explain some features of jquery knockout?

0 Answers  


Can you please explain the difference between javascript and jquery? : jquery mobile

0 Answers  


Difference between document.ready and window.onload? : jQuery Mobile

0 Answers  


Where jQuery code is getting executed?

0 Answers  


What are selectors in jquery?

0 Answers  


Why is only the first page of multi page document loaded? : jquery mobile

0 Answers  


Categories