DEV Community

Discussion on: Reveal the nth child of a div with id ‘hello’

Collapse
 
danielcamargo profile image
Daniel Camargo • Edited

If you want to make all the elements inside of hello visible, you need to set the style.display = block the each of them individually. You can do that by using a loop, like this example bellow:

var elements = document.getElementById('hello');
for (i=0; i<elements.children.length; i++) {
  var child = elements.children[i];
  child.style.display = 'block';
}

or if you want this the last one to be visible:

var elements = document.getElementById('hello');
elements.children[elements.children.length-1].style.display = 'block';