Latest web development tutorials

jQuery remove elements

By jQuery, you can easily delete the existing HTML elements.


Removing elements / Content

To delete elements and content, generally use the following two jQuery methods:

  • remove () - delete the selected element (and its children)
  • empty () - delete the child element selected from the elements

jQuery remove () method

jQuery remove () method removes the selected element and its children.

Examples

$("#div1").remove();

try it"


jQuery empty () method

jQuery empty () method to delete the selected element child elements.

Examples

$("#div1").empty();

try it"


Filter element is removed

jQuery remove () method also accepts a parameter that allows you to filter element to be deleted.

This parameter can be any jQuery selector syntax.

The following examples delete class = "italic" all <p> elements:

Examples

$("p").remove(".italic");

try it"