“JS Delete Element by ID” Kode Jawaban

JavaScript Hapus elemen dengan id

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

JavaScript Hapus elemen

//remove a dom element
var element = document.getElementById("someId");
	element.parentNode.removeChild(element);

//remove element from array
var colors=["red","green","blue","yellow"];
var blue=colors.splice(2, 1);//first arg is array index to remove
//colors is now ["red","green","yellow"]
Grepper

JavaScript Hapus elemen dengan contoh kode ID

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"]
Grepper

JS Delete Element by ID

document.getElementById("my-element").remove();
Talented Thrush

JS Delete Element

// delete an element from the dom
var elem = document.querySelector('#some-element');
elem.parentNode.removeChild(elem);


// keep element in dom
var elem = document.querySelector('#some-element');
elem.style.display = 'none';
Ariel Ferdman

Jawaban yang mirip dengan “JS Delete Element by ID”

Pertanyaan yang mirip dengan “JS Delete Element by ID”

Lebih banyak jawaban terkait untuk “JS Delete Element by ID” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya