jQuery Mobile Question:
Download Questions PDF

Explain chaining in jQuery?

Answer:

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.

$(document).ready(function(){
$('#dvContent').addClass('dummy');
$('#dvContent').css('color', 'red');
$('#dvContent').fadeIn('slow');
});​

The above jQuery code sample can be re-written using chaining.

​$(document).ready(function(){
$('#dvContent').addClass('dummy')
.css('color', 'red')
.fadeIn('slow');
});​

Not only functions or methods, chaining also works with events in jQuery

Download jQuery Mobile Interview Questions And Answers PDF

Previous QuestionNext Question
Can we include multiple version of jQuery?Tell me how to write browser specific code using jQuery?