I have a function for my rpg game that simulates grabbing an element in a create js container object by removing it from the container (thereby removing it from the stage) when the player gets near it.
function grabIt(NPC_id, index) {
console.log(ContainerOfAnimals.children[index].id);
var childToRemove = document.getElementById(ContainerOfAnimals.children[index]);
console.log(childToRemove);
ContainerOfAnimals.removeChild(childToRemove);
}
The first console.log gives correct id of child: 21
But when I want to grab the child container object using getElementById
, the child is null
.
Why is this?