mbejda
mbejda

Reputation: 1471

What would cause IE to error Object doesn't support property or method 'removeChild'?

I'm trying to remove 2 divs and append them at the same time. This is my script.

 parent = document.getElementById("wrap");
        if(parent){
        child =  document.getElementById("chart1b");
                  parent.removeChild(child);
           var g = document.createElement('div');
        g.id = "chart1b";
                  parent.appendChild(g);
        }
        parent2 = document.getElementById("pollwrap");
        child2 =  document.getElementById("chart2");

        parent2.removeChild(child2);

        var h = document.createElement('div');
        h.id = "chart2";

        parent2.appendChild(h)

In FireFox it works good. In Google Chrome it works awesome. In Safari it works Amazingly. In IE it crashes, burns, and errors start flying across my screen. Both parent divs are in the html so neither of them are missing. What could be the problem?

Upvotes: 1

Views: 1275

Answers (2)

david
david

Reputation: 4278

To start you have undeclared variables parent, child, parent2, child2. Define those and see what happens?

Upvotes: 2

Michael Sazonov
Michael Sazonov

Reputation: 1533

Try document.parent.removeChild or document.body.removeChild

Upvotes: 2

Related Questions