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 |
Differentiate between calling stop (true, true) and finish method?
Which is the fastest selector in jQuery?
Explain the animate function.
Does jquery 2.0 supports ie? : jquery mobile
Do we need to add jQuery file in both Master and Content page?
Change the url for a hyperlink using jquery?
What is jQuery plugin and what is the advantage of using plugin?
Need to add jQuery file in both Master and Content page?
What are jquery plugins?
What is the use of css() method in jquery?
Can we use protocol less URL while referencing jQuery from CDNs?
How to multiple version of jQuery?