Sometimes, we want to make a div visible and invisible with JavaScript.
In this article, we’ll look at how to make a div visible and invisible with JavaScript.
How to make a div visible and invisible with JavaScript?
To make a div visible and invisible with JavaScript, we set the style.visibility
property.
For instance, we write
const div = document.getElementById("div_id");
div.style.visibility = "visible";
to select the div with getElementById
.
And then we make it visible by setting style.visibility
to 'visible'
.
Likewise, we write
const div = document.getElementById("div_id");
div.style.visibility = "hidden";
to select the div with getElementById
.
And then we make it visible by setting style.visibility
to 'hidden'
.
Conclusion
To make a div visible and invisible with JavaScript, we set the style.visibility
property.