Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dom
html
communitycreator

What is the HTML DOM remove() method?

Ayush Trivedi

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The remove() method removes an element from the HTML DOM. It is applied on the element which we want to remove.

Parameter

This method does not require any parameters.

Return value

This method does not return anything.

Code

Let’s write the code to remove an element from the HTML:

Explanation

  • Line 5: We have a p paragraph element with simple text.
  • Line 7: We have another p element with an elem id which is removed from the HTML page.
  • Line 9: We write a button tag with a function change() binded with the onclick event. The function is called when the user clicks on it.
  • Line 12: We write the change() function inside the script tag .
  • Line 13: We use getElementById() to get the paragraph element with the elem id and assign it in a variable.
  • Line 14: We apply the remove() method on the variable which is to be removed.

Output

When we click the button, the paragraph element with the text is removed and can not be accessible in DOM again.

RELATED TAGS

dom
html
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring