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 |
What is each() function in jQuery? How do you use it?
What is the difference between onload() and document.ready()?
Differences Between jQuery .bind() and .live()?
What are selectors in jquery mean ?
Which is fast document.getElementByID('txtName') or $('#txtName').?
How to executed jquery selectors? : jquery mobile
Can you include multiple version of jQuery? If yes, then how they are executed?
Back onto jquery ui' can you see jquery ui making more of an impression in the future, lead by the current successes of jquery?
What does $("div.parent") will select?
What is jQuery code to select all links in first paragraph?
How we can set the html contents of an element in jquery?
Is jQuery a W3C standard?