Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

jQuery deletes the element


May 07, 2021 jQuery


Table of contents


jQuery - Remove the element


jQuery makes it easy to remove existing HTML elements.


Delete elements/content

To remove elements and content, there are two jQuery methods that you can typically use:

  • remove() - Delete selected elements (and their children)
  • empty() - Removes child elements from selected elements

jQuery remove() method

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

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

Try it out . . .

Tip: In the jQuery programming battle section of this site, you can practice how to use jQuery to remove an HTML element!


jQuery empty() method

The jQuery empty() method removes the child elements of the selected element.

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

Try it out . . .


Filter deleted elements

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

This parameter can be the syntax of any jQuery selector.

The following example removes all of the elements of class-"italic":

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

Try it out . . .