Given an HTML document containing div elements and the task is to remove the existing HTML elements using jQuery. To remove elements and its content, jQuery provides two methods:
- remove(): It removes the selected element with its child elements.
- empty(): It removes the child element from the selected elements.
<div id="Parent"> <div id="child1">child 1</div> <div id="child2">child 2</div> <div id="child3">child 3</div> </div>
Syntax: The following function clears the parent “div”
The following function clears all the child “divs”, but leaves the parent intact.
- Before clicking the button:
- After clicking the button:
- How to copy the content of a div into another div using jQuery ?
- How to overlay one div over another div using CSS
- How to center a div within another div?
- How to make an image center-aligned (vertically & horizontally) inside a bigger div using CSS?
- How to place a div inside an iframe for IE ?
- How to align content of a div to the bottom using CSS ?
- How to make div height expand with its content using CSS ?
- How to dynamically get the content width of a div using AngularJS ?
- How to detect and change the content/style of a div using jQuery ?
- How to use a div as content for Twitter's Popover?
- How to set div width to fit content using CSS ?
- How to dynamically get the content height of a div using AngularJS ?
- How to make div width expand with its content using CSS ?
- How to put a responsive clear button inside HTML input text field ?
- Projecting Content into Components with ng-content
- How to clear all options in a dropdown box?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.