Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 205
Manu Avatar asked Jan 29 '16 13:01

Manu


2 Answers

Use the pollyfill from MDN

if (!('remove' in Element.prototype)) {
    Element.prototype.remove = function() {
        if (this.parentNode) {
            this.parentNode.removeChild(this);
        }
    };
}
like image 149
epascarello Avatar answered Oct 03 '22 08:10

epascarello


Use this code instead:

var child = document.getElementById(id);
child.parentNode.removeChild(child);
like image 45
Bob Sponge Avatar answered Oct 03 '22 07:10

Bob Sponge