.addBack() in jQuery

It helps to add the previous element on the stack to the current element, optionally filtered by a selector.

.addBack()

// HTML Content
<ul>
<li>item 1</li>
<li>item 2</li>
<li class=”third-item”>item 3</li>
<li>item 4</li>
<li>item 5</li>
</ul>

// To apply yellow from “item 4” to “item 5”
$( “li.third-item” ).nextAll().css( “background-color”, “yellow” );

// To apply yellow from “item 3” to “item 5”
$( “li.third-item” ).nextAll().addBack().css( “background-color”, “yellow” );