Show and hide element via CSS style display - Javascript CSS Style Property

Javascript examples for CSS Style Property:display

Description

Show and hide element via CSS style display

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from  www.jav  a2  s  . c om
var elems = document.querySelectorAll('p,li');
for(var i = 0;i < elems.length; i++)
{
    elems[i].style.display = 'none';
}
    }

      </script> 
   </head> 
   <body> 
      <p>1</p> 
      <ul> 
         <li>2</li> 
      </ul>  
   </body>
</html>

Related Tutorials