Code has been added to clipboard!

Returning the Original Elements After Filtering With jQuery .end()

Reading time 1 min
Published Jun 14, 2019
Updated Sep 30, 2019

jQuery end: Main Tips

  • jQuery .end() method is useful when you're using chaining.
  • The jQuery .end() finishes the most recent filtering operation in the chain.
  • jQuery .end() method returns the original set of elements you had before manipulating the chain.

Usage and Syntax of .end()

If you use .find() or another filtering function on an jQuery chain, a newly wrapped element set is returned. jQuery .end() method concludes the filtering and returns to the original set of elements (before the execution of the first function).

The .end() function takes no arguments.

Example
$( "ul.list-1" )
  .find( ".demo" )
    .css( "background-color", "lightgreen")
  .end()
  .find( ".demo-bar" )
    .css( "background-color", "orange" );

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 28/01/2021
3176 People Used
Only 97 Left
Rating
5.0