Javascript Remove Element By Id Code Example

Example 1: Javascript Remove Element By Id Code Example

//removing element by ID
var element = document.getElementById("myElementID");
    element.parentNode.removeChild(element);

Example 2: Javascript Remove Element By Id Code Example

var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]

Tags:

3 Example