Advantages of method chaining:
- Selector is only evaluated once for multiple operations. Better performance, smaller code.
- Selector result can be used for multiple methods without having to assign it to a local variable. More compact code.
- Multiple methods can more compactly be put on one line.
- A lot more compact specifically when you want operations on consecutive different results such as
$(this).next().find("span.title").closest(".section").hide();
. Without chaining, you would need four different local variables where this needs none.
Disadvantages of chaining:
- The selector result has not been saved in a local variable for more complicated uses that can't be done only with chaining.
- Cramming too many consecutive chained methods on one line can compromise code readability if it extends to make a very long line of code. (One can still use chaining, but just insert occasional linebreaks in the chaining to avoid this).