The addBack method
The addBack method adds elements from the previous set to the current one (we are talking about one method chain), a selector can also be selectively passed to the method. The previous set is the set of elements that can be obtained using the end method.
Syntax
.addBack([selector]);
Example
Let's find the paragraph with #test, then find the parent of that paragraph with parent, append the found paragraph to its parent with addBack, and prepend it with the text '!' with prepend. This will result in both the paragraph and its parent having the text '!' at the beginning:
<div>
<p>text</p>
<p id="test">text</p>
<p>text</p>
</div>
$('p').parent().addBack().prepend('!');
HTML the code will look like this:
<div>
!
<p>!text</p>
<p id="test">!text</p>
<p>!text</p>
</div>