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

Differentiate among .empty() vs .remove() vs .detach() in jquery.

628


How to call a method inside code-behind using jquery?

614


How to select combobox select value and text using jquery?

579


What are the advantages of using cdn?

617


How to select all elements using jQuery?

672


How do you select an item using css class or id and get the value by use of jquery.

620


Which selector has better performance id or class and why?

555


Explain is jquery replacement of java script? : jquery mobile

607


How to check if number is numeric while using jquery 1.7+? : jquery mobile

616


Explain the common methods of sending a request to a server.

620


What is the difference between jquery and javascript?

623


What is the jQuery code to select all links inside the paragraph?

635


How to redirect to another page using jquery?

610


What are some of the ways to provide effects? : jQuery Mobile

590


what does $("div") will select? : jquery mobile

620