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?
Explain the use of jquery .each() function? : jquery mobile
Is numeric in jquery?
Why html 5 inputs look different across devices and browsers? : jquery mobile
What is the goal of cdn and what are the advantages of using cdn?
How we can get the value of a radio button using jquery?
How to use migrate jquery plugin if possible? : jquery mobile
How to search for descendant elements that match the specified selectors using ?
Explain the difference between .js and .min.js?
What is the difference between calling stop(true,true) and finish method?
How we can set the html contents of an element in jquery?
Tell me how to check if number is numeric while using jquery 1.7+? : jquery mobile