jQuery empty() Method

jQuery empty() method remove all child nodes and content of the selected elements.

jQuery empty() method removes not only child elements, but also removes any text within the set of selected elements.

Syntax

This syntax represent to the empty() method

$(selector).empty();

This method does not accept any arguments.

Example: remove text content

Remove text content on selected elements.

$(document).ready(function(){
  $("button").click(function(){
    $("#p1").empty();
  });
});

Run it...   »

Example: remove all child nodes and text content

Remove all child nodes as well as text content on selected element using empty() method.

$(document).ready(function(){
  $("button").click(function(){
    $("#p1").empty();
  });
});

Run it...   »