jQuery | empty() with Examples
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:

Recommended Posts:
- jQuery | :empty Selector
- How to check an HTML element is empty using jQuery ?
- jQuery | first() with Examples
- jQuery | after() with Examples
- jQuery | eq() with Examples
- jQuery | one() with Examples
- jQuery | last() with Examples
- jQuery | on() with Examples
- jQuery | has() with Examples
- jQuery | val() with Examples
- jQuery | andSelf( ) with Examples
- jQuery | noConflict() with Examples
- jQuery | not() method with Examples
- jQuery | submit() with Examples
- jQuery | clearQueue() with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



