Only display the first child of a div - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Only display the first child of a div

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 w  ww  . j  a va 2 s. co  m*/
var test1 = document.getElementById("test1").firstElementChild.nextElementSibling;
while (test1) {
    test1.style.display = "none";
    test1 = test1.nextElementSibling;
}
    }

      </script> 
   </head> 
   <body> 
      <div id="test1"> 
         <p>Lorem ipsum</p> 
         <p>Lorem ipsum</p> 
         <p>Lorem ipsum</p> 
      </div>  
   </body>
</html>

Related Tutorials