- empty()
- remove()
- html()
Ex: $('#divTestArea1').empty();
Ex: $('#divTestArea1').remove();
Ex: $('#divTestArea1').html(‘’);
When the preceding script executes, it removes all its child elements.
- <body>
- <a href="#" id="emptyLink">empty() div</a>
- <a href="#" id="removeLink">remove() div</a>
- <a href="#" id="htmlLink">html() div</a>
- <div id="divTestArea1" style="height: 100px; width: 300px; border: 1px solid silver; background-color: #eee;">
- <b>Bold text</b>
- <i>Italic text</i>
- </div>
- </body>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
- <script>
- $(document).ready(function(){
- $("#emptyLink").click(function(){
- $('#divTestArea1').empty();
- });
- $("#removeLink").click(function(){
- $('#divTestArea1').remove();
- });
- $("#htmlLink").click(function(){
- $('#divTestArea1').html('');
- });
- });
- </script>

Figure 1: Displaying HTML content before doing an operation
Clicking on the first link executes empty(). It removes all the child elements of the div.
Figure 2 shows that a div exists but the child nodes do not exist. Compare Figure 1 with Figure 2 and you will see the difference.

Figure 2: Displaying HTML content after empty() executes
Clicking on the second link executes remove() of jQuery. It removes the div with all its child elements.
Figure 3 shows the div is not there. That means the remove() method removes a selected element and all its child elements.

Figure 3: Displaying HTML content after remove() executes
Lastly empty() and html() work the same, that means they remove child nodes only. But empty() provides faster performance to remove all child elements as compared with html().
Conclusion
Previously we discussed 3 options to remove elements using jQuery. First, if you have the requirement to delete only child elements of a selected element (div/span/..) then use empty(). Second, if you want to delete a selected element with all its child elements then use remove(). In this way jQuery helps to remove child nodes, emptying a div, table, span, etc.

Ravi PatelPosted Dec 7, 2015, 11:12 PM
Nicely explained
RakeshPosted Aug 23, 2015, 1:02 AM
Good one
Gowtham KPosted Aug 22, 2015, 10:13 PM
Good one
Santhakumar MunuswamyPosted Aug 22, 2015, 6:12 AM
Nice Article. Thanks for sharing
Rajeesh MenothPosted Aug 22, 2015, 1:51 AM
Good One Manas Mohapatra
Karthikeyan KPosted Aug 21, 2015, 11:06 PM
Good one sir...Thanks for share