.empty() Returns: jQuery

Description: Remove all child nodes of the set of matched elements from the DOM.

  • version added: 1.0.empty()

This method removes not only child (and other descendant) elements, but also any text within the set of matched elements. This is because, according to the DOM specification, any string of text within an element is considered a child node of that element. Consider the following HTML:

<div class="container">
  <div class="hello">Hello</div>
  <div class="goodbye">Goodbye</div>

We can target any element for removal:


This will result in a DOM structure with the Hello text deleted:

<div class="container">
  <div class="hello"></div>
  <div class="goodbye">Goodbye</div>

If we had any number of nested elements inside <div class="hello">, they would be removed, too. Other jQuery constructs such as data or event handlers are erased as well.


Removes all child nodes (including text nodes) from all paragraphs

<!DOCTYPE html>
  p { background:yellow; }
  <script src="http://code.jquery.com/jquery-latest.js"></script>
    Hello, <span>Person</span> <a href="javascript:;">and person</a>

  <button>Call empty() on above paragraph</button>
    $("button").click(function () {