jQuery addBack() Method Explained With Easy Examples
Table of Contents
- jQuery addBack Method
jQuery addBack Method
To incorporate the initial set of elements into the current situation, use the
addBack() method. The selector can filter it if desired. It's a built-in jQuery method.
Syntax of addBack method in jQuery
The optional parameter of the
addBack() method is the selector mentioned in the above syntax. It specifies a string containing a selector expression against which should match the elements.
Example of jQuery addBack method
In this example, the
addBack() method is applied to the paragraph element with id = "p1". The
nextAll() method is used here to select the next paragraph siblings of the paragraph element with id = "p1."
It is an example of using the addBack() method.divParagraph 1Paragraph 2Paragraph 3Click the below button to see the effect. Click me Here, we see that paragraph 1 is also selected. This is due to the addBack() method. If we do not use it, only 2nd and 3rd paragraphs will get selected.
You will see the final output on clicking the ‘Click me’ button, as shown below: