Using jQuery you can remove existing HTML elements or content form your document.
Following are the jQuery remove methods that allow us to remove the existing content:
empty()
remove()
unwrap()
removeAttr()
jQuery empty() Method:
The jQuery empty() method allows us to removes all child elements as well as other successor elements and the text content within the selected elements from the DOM.
In the above example when you click on the button it will remove the content inside of the selected elements.
jQuery remove() Method:
The jQuery remove method allows us to remove the selected elements from the DOM as well as everything inside it.
In the following example, all <p> elements are removed with the class .demo from the DOM on button click, nested elements inside these paragraphs will also be removed.
Example:
$(document).ready(function(){
// Removes paragraphs with class "demo" from DOM on button click
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok