Error with getElementById(id).remove() in IE11 [duplicate]

半城伤御伤魂 提交于 2019-12-23 09:23:03

问题


I have this code:

document.getElementById(id).remove();

But, IE give me an error with this function. Do you know an other way for make this remove?


回答1:


Use this code instead:

var child = document.getElementById(id);
child.parentNode.removeChild(child);



回答2:


Use the pollyfill from MDN

if (!('remove' in Element.prototype)) {
    Element.prototype.remove = function() {
        if (this.parentNode) {
            this.parentNode.removeChild(this);
        }
    };
}


来源:https://stackoverflow.com/questions/35085503/error-with-getelementbyidid-remove-in-ie11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!