August 2016
Beginner to intermediate
847 pages
17h 28m
English
Chaining jQuery methods allows you to call a series of methods on a selection without temporarily storing the intermediate values. This is possible because every setter method that we call returns the selection on which it was called. This is a very powerful feature and you will see it being used by many professional libraries. Consider the following example:
$( '#button_submit' )
.click(function() {
$( this ).addClass( 'submit_clicked' );
})
.find( '#notification' )
.attr( 'title', 'Message Sent' );xIn this snippet, we are chaining click(), find(), and attr() methods on a selector. Here, the click() method is executed, and once the execution finishes, the find() method locates the element with the notification ID and changes its title ...