Use CSS ">" selector to select particular div using document.querySelector - Javascript DOM

Javascript examples for DOM:Document querySelector

Description

Use CSS ">" selector to select particular div using document.querySelector

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.ja v  a2  s . c  om
document.querySelector('body > div + div').style.color = 'red';
    }

      </script> 
   </head> 
   <body> 
      <div>
          Mango 
      </div> 
      <div>
          Apple 
      </div> 
      <div>
          Satsuma 
      </div> 
      <div>
          Watermelon 
      </div>  
   </body>
</html>

Related Tutorials