.andSelf()    **DEPRECATED 1.8 and REMOVED 3.0** JQ 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 removed in jQuery 3.0 and is now used as an alias for the .addBack() method added in jQuery 1.8 which should be used instead.

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 containing this set of elements as well as the previous set of elements retrieved from the jQuery stack.

Related Tutorials

jQuery Basic Tutorials - Lesson 7 - Other Traversal