vanilla JavaScript set style on body

后端 未结 3 1545
梦如初夏
梦如初夏 2020-12-15 03:08

Why does this not work?

Using vanilla JavaScript to set the style on body tag?


   
       test
   &l         


        
相关标签:
3条回答
  • 2020-12-15 03:28

    I used the following solution:

    <script>
        function changeDisplay(){
            document.body.style.display = 'block';
        }
    
        setTimeout(function () { changeDisplay(); }, 0);
    </script>
    
    0 讨论(0)
  • 2020-12-15 03:33

    If you want the body tag you can simply use document.body. See the demo: http://jsfiddle.net/TH3Yd/

    0 讨论(0)
  • 2020-12-15 03:40

    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";
    
    0 讨论(0)
提交回复
热议问题