Adding Elements with addBack in jQuery
There is also a similar method addBack, which adds the previous set to the current one.
Let's look at the following example. Let's say the HTML code looks like this:
<div>
<p>text</p>
<p id="test">text</p>
<p>text</p>
</div>
Let's find the paragraph #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 '!' using prepend. This will result in both the paragraph and its parent having the text '!' at the beginning:
$('p').parent().addBack().prepend('!');
Find the parent of li with the class www (the class of the element li), add this li to the parent using addBack and color them red.