.andSelf()
methodThe .andSelf()
method in jQuery is used to add the previous set of elements on the stack to the current set.But it has been deprecated and please use .addBack()
instead.
.andSelf()
method Syntax.andSelf()
.andSelf()
method ExampleThe selector $( "li.third" )
get a set containing element item 3
.
The method .nextAll()
push the set of item 4,5 onto the stack.
Then andSelf
merges those two sets together,so we would get a jQuery object containing elements [<li.third>,<li>,<li>]
HTML
<ul> <li>item 1</li> <li>item 2</li> <li class="third">item 3</li> <li>item 4</li> <li>item 5</li> </ul>
jQuery
$('li.third').nextAll().andSelf()
Result
[<li.third>,<li>item 4</li>,<li>item 5</li>]`