The Wayback Machine - https://web.archive.org/web/20230512160300/https://www.geeksforgeeks.org/jquery-empty-with-examples/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

jQuery | empty() with Examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The empty() method is an inbuilt method in jQuery which is used to remove all child nodes and its content for the selected elements.

Syntax:

$(selector).empty()

Parameter: This method does not accept any parameter.

Return Value: This method returns the selected element with the specified changes made by empty() method.

Below example illustrates the empty() method in jQuery:

Example:




<!DOCTYPE html>
<html>
    <head>
        <title>The empty Method</title>
        <script src=
        </script>
          
        <!-- jQuery code to show the working of this method -->
        <script>
            $(document).ready(function() {
                $("button").click(function() {
                    $("body").empty();
                });
            });
        </script>
        <style>
            div {
                width: 200px;
                height: 100px;
                margin: 10px;
                padding: 20px;
                background-color: lightgreen;
                font-weight: bold;
                font-size: 20px;
            }
               
            button {
                margin: 10px;
            }
        </style>
    </head>
    <body>
        <div>
            Hello !
            <p>Welcome to <span>GeeksforGeeks</span>.</p>
        </div>
        <!-- click on this button to see the change -->
        <button>Click here..!</button>
    </body>
</html>

Output:
Before click on the button:

After click on the button nothing will display:


My Personal Notes arrow_drop_up
Last Updated : 13 Feb, 2019
Like Article
Save Article
Similar Reads