Error with getElementById(id).remove() in IE11

Manu picture Manu · Jan 29, 2016 · Viewed 9.3k times · Source

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?

Answer

Bob  Sponge picture Bob Sponge · Jan 29, 2016

Use this code instead:

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