问题
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