.andSelf()    **DEPRECATED**S2C Home « Traversal « .andSelf()

Stack retrieval.

Description

The .andSelf() method is used to add the previous set of elements on the jQuery stack to the current set of elements.

  • When we chain our traversal or filtering methods together, many of the jQuery methods used operate on an existing jQuery instance and produce a new jQuery object that match a different set of elements. jQuery maintains the previous set of elements, as well as the new set of elements as an internal stack. We can visualize this stack where the newest set of elements is 'pushed' onto the stack. As we continue through our jQuery chain, each new traversal or filtering method will create a new set of elements that gets 'pushed' onto the stack. The .andSelf() method allows us to add the previous set of elements from the stack to the current set of elements.

This method was deprecated in jQuery 1.8 and is now used as an alias for the .addBack() method added in jQuery 1.8.

Syntax


Signature Description
.andSelf()Add the previous set of elements on the jQuery stack to the current set of elements.

Parameters

None.

Return

A jQuery object either containing the elements matched or empty.

go to home page Homepage go to top of page Top