Chaining in jQuery means allowing multiple function/ selectors to an element in the web page.
Example-
$(document).ready(function(){
$('#mybox').css('font', '10px');
$('#mybox').addClass('new');
$('#mybox').fadeIn('slow');
});
By using chaining we can write above code as-
$(document).ready(function(){
$('#mybox').css('color', '10px').addClass('new').fadeIn('slow');
});
Note:-
- Advantage of chaining is that we can mange our code in a simple and short manner.
- The script execution becomes faster because the element will search only single time to perform multiple operation.
0 Comment(s)