remove() in javascript

remove() method in javascript

remove() method is used to remove the specified element.

If the given element contains any child node it will also be removed.

Example - Get attribute value of the given element

Try Yourself

Example Explanation

  • When the button in clicked Javascript function is called.
  • Then we are getting the specific p element (document.getElementById('pID');) using its id value and storing it in elem variable.
  • Next using the remove() method, we are removing the specified element (elem.remove();).