1Removing an element is much easier, as it only requires the element's ID.
21. function removeElement(elementId) {
32. // Removes an element from the document.
43. var element = document. getElementById(elementId);
54. element. parentNode. removeChild(element);
65. }
7
8Example:
9<h1>The remove() Method</h1>
10
11<p>The remove() method removes the element from the DOM.</p>
12
13<p id="demo">Click the button, and this paragraph will be removed from the DOM.</p>
14
15<button onclick="myFunction()">Remove paragraph</button>
16
17<script>
18function myFunction() {
19 var myobj = document.getElementById("demo");
20 myobj.remove();
21}
22</script>
1var elem = document.getElementById("myDiv");
2elem.parentNode.removeChild(elem);
1function arrayRemove(arr, value)
2{
3 return arr.filter(function(ele){
4 return ele != value;
5 });
6}
7//var result = arrayRemove(array, 6);// result = [1, 2, 3, 4, 5, 7, 8, 9, 0]
1
2
3 var ar = [1, 2, 3, 4, 5, 6];
4
5 ar.pop(); // returns 6
6 console.log( ar ); // [1, 2, 3, 4, 5]
7
8 ar.shift(); // returns 1
9 console.log( ar ); // [2, 3, 4, 5, 6]
10
11
12 for ( var i = 0; i < ar.length; i++){
13 if (ar[i] === 2 /*Value u wont to remove*/)
14 ar.splice(i, 1);
15 }
16 console.log( ar ); // [1, 3, 4, 5, 6]
17
18
19
1<div id="div-01">Here is div-01</div>
2<div id="div-02">Here is div-02</div>
3<div id="div-03">Here is div-03</div>
4