What is chaining in jQuery?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to divide a page into parts using jquery mobile? : jquery mobile

564


How to submit a form without submit button using jquery?

556


What is a cdn? : jQuery Mobile

565


How To Use Ajax In Jquery?

539


Create a plugin that would add and remove a class on hover.

509






How can we show and hide an element via jquery?

536


What is jquery.size()? : jquery mobile

548


What are the methods used to provide effects?

583


What is the difference between the id selector and class selector in jquery?

546


Explain some of the key concepts of good code organization patterns.

577


Define the script build up by jquery?

583


How to programmatically trigger a click event that's being handled by jquery?

546


Can we add more than one ‘document.ready’ function in a page?

640


differentiate between bind() vs live() vs delegate() methods in jquery.

528


How to search for descendant elements that match the specified selectors using ?

510