vanilla JavaScript set style on body
Because getElementsByTagName()
returns a NodeList, not a single element. Treat it as array:
document.getElementsByTagName("body")[0].style.display = "block";
Or even simpler in case of body
:
document.body.style.display = "block";
If you want the body
tag you can simply use document.body
. See the demo.
console.time("show body");
document.body.style.display = "none";
setTimeout(function () {
console.timeEnd("show body");
document.body.style.display = "block";
}, 3000);
<h1>Hello World!</h1>
I used the following solution:
<script>
function changeDisplay(){
document.body.style.display = 'block';
}
setTimeout(function () { changeDisplay(); }, 0);
</script>