One of jQuery's most powerful features is method chaining — calling multiple methods sequentially on the same line. Each traversal method returns a new jQuery object representing the new selection. The .end() method steps back to the previous jQuery object in the chain, letting you work with multiple selections without breaking the chain or creating new variables.
Why .end() Matters
Without .end(), each traversal permanently changes the selection context for subsequent calls. With .end(), you can make targeted modifications to a sub-selection and then return to the original set to continue working — all within a single statement.
Practical Patterns
Use chaining with .end() to build readable single-statement blocks that modify multiple related elements: a container and its children, a list and its first item, or a form and a specific input.
.find().css().end()— modify descendants then return to parent.filter().show().end().filter().hide()— split and style subsets.addBack()— adds the previous set to the current one (union)