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 |
How to resolve conflicts with other libraries?
How can you apply a style on an element using jQuery?
What is event preventdefault () and event stoppropagation () in jquery?
List a few features of jquery mobile? : jQuery Mobile
How can events be prevented from stopping to work after an ajax request?
Explain all the ways to include jquery in a page?
How can you delay document.ready until a variable is set?
What is jquery datepicker in jquery?
How do you install/use jquery in a project. What is the minimum setup needed to start using jquery.
Define "beforesend(xhr)" paremeter of jquery ajax method?
Is jQuery a library for client scripting or server scripting?
How do you stop the currently-running animation? : jquery mobile