Programmers learn & share
0 votes
397 views

Problem :

Facing following javascript issue
failed to execute 'removechild' on 'node': the node to be removed is not a child of this node.
by (6.9k points)   | 397 views

1 Answer

0 votes

Solution :

I think your myCoolDiv element is not a child of the player container. It is the child of the div that you have created as a  wrapper for it Note : markerDiv in the first part of the code. That is why it is failing so removeChild only removes the children and not the descendant.

So you must remove the wrapper div.

Following is the "not adding it at all" option:

e.g.

var markerDiv = document.createElement("div");

markerDiv.innerHTML = "<div id='MyCoolDiv' style='color: #2b0808'>123</div>";

document.getElementById("playerContainer").appendChild(markerDiv.firstChild);

// -------------------------------------------------------------^^^^^^^^^^^

setTimeout(function(){

    var myCoolDiv = document.getElementById("MyCoolDiv");

    document.getElementById("playerContainer").removeChild(myCoolDiv);

}, 1500);

<div id="playerContainer"></div>

by (36.1k points)  
2,245 questions
2,807 answers
60 comments
241 users