Code has been added to clipboard!

Removing Child Elements With jQuery .empty()

Reading time 2 min
Published Jan 18, 2018
Updated Oct 2, 2019

jQuery empty: Main Tips

  • The jQuery .empty() method removes all descendant nodes from selected DOM elements.
  • All strings of text are also considered child elements and thus removed.
  • To remove elements completely, use the .remove() method. To remove them but keep their data and event handlers, use .detach().

Usage of jQuery .empty() Explained

The .empty() jQuery method removes the children and nodes of the specified elements. All you need to do is specify a selector to match the target elements:


Check the example with the selector defined as <p> below:

$(document).ready(() => {
	$("button").click(() => {

Note: if you make jQuery remove all children elements, nested elements will be deleted as well.

Differences Between jQuery .empty(), .detach() and .remove()

There are three methods used for removing elements in jQuery: .empty(), .detach() and .remove(). A beginner might find it a bit confusing. You will find the differences of these methods explained in the table below:

Method Definition
.empty() Removes the content and child elements from the selected element, but does not remove the element itself.
.detach() Removes all child elements with the selected element, but keeps data and event handlers, so you may re-add them at a later time.
.remove() Removes all child elements, data and events with the selected element.

Compare the methods in the example below:

$(document).ready(function () {

  $("button.btn-remove").click(function () {

  $("button.btn-empty").click(function () {

  $("button.btn-detach").click(function () {

Latest Coupon Found:



Learn the skills of tomorrow

The best time to learn programming is now - follow this link to access 100+ coding courses and enjoy learning at a very low cost!

Expiration date: 15/05/2021
2287 People Used
Only 92 Left