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

What are the popular jquery cdn? : jquery mobile

0 Answers  


What is the use of jquery.data()?

0 Answers  


Explain is jquery replacement of java script? : jquery mobile

0 Answers  


What is the use of serialize method in jQuery?

0 Answers  


When can you use jquery?

0 Answers  


What is the difference between event.stopPropagation and event.stopImmediatePropagation?

1 Answers  


Explain various methods to make ajax request in jquery? : jquery mobile

0 Answers  


How to debug jQuery?

0 Answers  


Explain jquery $.ajax() method?

0 Answers  


How to disable cut,copy and paste in TextBox using jQuery?

0 Answers  


Define the script build up by jquery?

0 Answers  


Can you please explain the difference between event.preventdefault and "return false"? : jquery mobile

0 Answers  


Categories