Open In App

jQuery empty() Method

Last Updated : 10 Jul, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The empty() method is an inbuilt method in jQuery that is used to remove all child nodes and their 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 the empty() method.

The below example illustrates the empty() method in jQuery:

Example: In this example, we are using the jquery empty() method.

html




<!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:

jquery-11



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads