var elem = document.getElementById("yourid");elem.parentElement.removeChild(elem);
对于删除所有元素,例如某个类名:
var list = document.getElementsByClassName("yourclassname");for(var i = list.length - 1; 0 <= i; i--)if(list[i] && list[i].parentElement)list[i].parentElement.removeChild(list[i]);
// Removing a specified element when knowing its parent nodevar d = document.getElementById("top");var d_nested = document.getElementById("nested");var throwawayNode = d.removeChild(d_nested);