The end method
The end method returns the previous set of elements in the current method chain.
Syntax
.end();
Example
In the following example we will find all paragraphs, then select the paragraphs with class www from those found using filter and append the text '!' to the end of them using append, then go back to the previous set (which is the $('p') set) using end and append the text '?' to the end of them. It turns out that paragraphs with class www will have text '!?', and regular paragraphs will have text '?':
<p class="www">text</p>
<p class="www">text</p>
<p>text</p>
<p>text</p>
$('p').filter('.www').append('!').end().append('?');
HTML the code will look like this:
<p class="www">text!?</p>
<p class="www">text!?</p>
<p>text?</p>
<p>text?</p>