Javatpoint Logo
Javatpoint Logo

jQuery end() method

The end() method in jQuery is used to end the most recent filtering operation in the current chain and returns the matched set of elements to its previous state. This method is used without any argument.

The end() method is useful when jQuery is used for chaining purposes.

Syntax

This method does not accept any argument.

Now, let's understand the working of the end() method using some illustrations.

Example1

It is a simple example of using the end() method. Here, the chain will first search the paragraph elements with span and b elements inside them, and then on clicking the button, the span elements in the paragraph elements will get selected.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery end() method

After clicking the given button, the output will be -

jQuery end() method

Example2

In this example there are two methods in the chain that are the find() method and first() method, and the background colors of the paragraph elements should be changed accordingly. But on clicking the given button, the end() method will remove the last method in the chain and change the background color of paragraph elements including the span element.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery end() method

After clicking the given button, the output will be -

jQuery end() method





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA