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 check if number is numeric while using jquery 1.7+? : jquery mobile

0 Answers  


How do you check if an element is empty?

1 Answers  


What is jquery.length? : jquery mobile

0 Answers  


Why do we use jQuery?

1 Answers  


What does $("div.parent") will select?

1 Answers  






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

0 Answers  


How do you select element by ID in jQuery?

1 Answers  


Explain slidetoggle() effect.

0 Answers  


What is jquery.size()? : jquery mobile

0 Answers  


Explain width() vs css(‘width’)?

0 Answers  


How can we show and hide an element via jquery?

0 Answers  


How JavaScript and jQuery are different?

1 Answers  


Categories