11

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?

Manu
  • 652
  • 3
  • 11
  • 22

2 Answers2

33

Use this code instead:

var child = document.getElementById(id);
child.parentNode.removeChild(child);
Bob Sponge
  • 4,708
  • 1
  • 23
  • 25
19

Use the pollyfill from MDN

if (!('remove' in Element.prototype)) {
    Element.prototype.remove = function() {
        if (this.parentNode) {
            this.parentNode.removeChild(this);
        }
    };
}
epascarello
  • 204,599
  • 20
  • 195
  • 236