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 load jQuery locally when CDN fails?

1 Answers  


How to execute jQuery code after the DOM is ready?

0 Answers  


What are the slow selectors in jquery? : jquery mobile

0 Answers  


How to resolve conflicts with other libraries?

0 Answers  


Will Events Are Also Copied On Clone In Jquery?

0 Answers  






Tell me how do you stop the currently-running animation? : jquery mobile

0 Answers  


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

0 Answers  


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

0 Answers  


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

0 Answers  


How does jquery store data related to an element?

0 Answers  


What is the difference between prop and attr?

0 Answers  


How to work with jQuery parent(), children() and siblings()?

0 Answers  


Categories