Javascript examples for DOM:Element firstElementChild
Add CSS class name to first child element
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style id="compiled-css" type="text/css"> .current {//from w ww .java2 s . c o m color: red; } </style> <script type="text/javascript"> window.onload=( function() { document.getElementsByTagName('nav')[0].firstChild.className = "current"; }); </script> </head> <body> <nav> <a>test</a> </nav> </body> </html>