Show and hide element by setting CSS style display - Javascript CSS Style Property

Javascript examples for CSS Style Property:display

Description

Show and hide element by setting CSS style display

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Untitled</title> 
      <script>
 function myFunction(){//from  w w w  .j ava 2  s. c  o  m
    var x=document.getElementsByClassName('demo')[0];
    if(x.style.display==='none'){
       x.style.display='block';
    }else{
       x.style.display='none';
    }
}

      </script> 
   </head> 
   <body> 
      <ul> 
         <li onclick="myFunction()"> THIS IS DEMO</li> 
      </ul> 
      <div class="demo">
         Demo
      </div>  
   </body>
</html>

Related Tutorials