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

How to resolve conflicts with other libraries?

0 Answers  


How can you apply a style on an element using jQuery?

0 Answers  


What is event preventdefault () and event stoppropagation () in jquery?

0 Answers  


List a few features of jquery mobile? : jQuery Mobile

0 Answers  


How can events be prevented from stopping to work after an ajax request?

0 Answers  






Explain all the ways to include jquery in a page?

0 Answers  


How can you delay document.ready until a variable is set?

0 Answers  


What is jquery datepicker in jquery?

0 Answers  


How do you install/use jquery in a project. What is the minimum setup needed to start using jquery.

0 Answers  


Define "beforesend(xhr)" paremeter of jquery ajax method?

0 Answers  


Is jQuery a library for client scripting or server scripting?

1 Answers  


How do you stop the currently-running animation? : jquery mobile

0 Answers  


Categories