The remove()
method removes an element from the HTML DOM. It is applied on the element which we want to remove.
This method does not require any parameters.
This method does not return anything.
Let’s write the code to remove an element from the HTML:
p
paragraph element with simple text.p
element with an elem
id which is removed from the HTML page.change()
binded with the onclick
event. The function is called when the user clicks on it.change()
function inside the script tag .getElementById()
to get the paragraph element with the elem
id and assign it in a variable.remove()
method on the variable which is to be removed.When we click the button, the paragraph element with the text is removed and can not be accessible in DOM again.