Javascript DOM HTML Element remove Method

Introduction

Remove the selected element from the document:

var myobj = document.getElementById("demo"); myobj.remove();

View in separate window

<!DOCTYPE html>
<html>
<body>

<h1>The remove() Method</h1>

<p>The remove() method removes the element from the DOM.</p>

<p id="demo">Click the button, and this paragraph will be removed from the DOM.</p>

<button onclick="myFunction()">Remove paragraph</button>

<script>
function myFunction() {/* w ww. j  a v  a 2  s  .c om*/
  var myobj = document.getElementById("demo");
  myobj.remove();
}
</script>

</body>
</html>

The remove() method removes the specified element from the DOM.


element.remove();



PreviousNext

Related