hide Html elements by using javascript

In addition to DevlshOne's answer, you could also use css to make it not display:

var divOne = document.getElementById('1');
divOne.style.display='none';

There's a difference between the two. With visibility hidden, the space will still be consumed by the div, but you can't see it. With display='none', its as if its not there.

Pick the better one for you.


Answers above are all basically correct, but you need to be aware of a difference between display = "none" & visibility = "hidden". With display "none" the element is removed from the layout of elements on the page. With visibility "hidden" the element still occupies its space, you just don't see it anymore.


var divOne = document.getElementById('1');
divOne.style.visibility = 'hidden';

document.getElementById on MDN


you will need to use something like this:

document.getElementById("1").style.display = "none";