Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

jQuery | andSelf( ) with Examples

  • Last Updated : 12 Feb, 2019

The andSelf( ) is an inbuilt method in jQuery which is used to add the previous set of elements to the current set. This method adds previous DOM tree elements to the current set and maintains them in the internal stack which will take care of changes to the matched set of elements. Document Object Model(DOM) is a World Wide Web Consortium standard. This defines for accessing elements in the DOM tree.

andSelf( )(selector);

Parameters: It does not accept any parameter.
Return Value: It returns all added element against the specified selector.
jQuery code to show the working of andSelf( ) method:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

    <script type="text/javascript" 
        $(document).ready(function() {
        div {
            margin: 5px;
            padding: 5px;
        .border {
            border: 2px solid green;
        .background {
            background: green;
        <p>This is first paragraph.</p>
        <p>This is second paragraph.</p>

Here border would be added to previous selection which is a division and then second selection which is paragraphs.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!