Get second child using CSS via document.querySelector - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Style

Description

Get second child using CSS via 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(){/*w ww. j  av  a  2  s  .  co m*/
var secondChild = document.querySelector('.parent > td:nth-of-type(2)');
console.log(secondChild); // <td>element two</td>
    }

      </script> 
   </head> 
   <body> 
      <table> 
         <tbody>
            <tr class="parent"> 
               <td>element one</td> 
               <td>element two</td> 
            </tr> 
         </tbody>
      </table>  
   </body>
</html>

Related Tutorials