How to remove dom element? [duplicate]
Ok I've been so spoiled with Jquery that I don't even know how to remove an element anymore with plain Javascript.
So I have this which I would like to remove with Javascript.
Any help appreciated.
Try this
function RemoveElement(elemID) {
var elem = document.getElementById(elemID);
if (elem.parentNode) {
elem.parentNode.removeChild(elem);
}
}
Node.removeChild
is the method, see documentation here: https://developer.mozilla.org/En/DOM/Node.removeChild
Example:
var parent = document.getElementById("mydiv");
var child = document.getElementById("other");
parent.removeChild(child);
like:
container.removeChild(child);
精彩评论