开发者

How to remove dom element? [duplicate]

This question already has answers here: JavaScript DOM remove element (4 answers) Closed 8 ye开发者_运维百科ars ago.

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜