Get element attribute with getAttribute method - Javascript DOM

Javascript examples for DOM:Element getAttribute

Description

Get element attribute with getAttribute method

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  w w .ja v a2s. c  o  m*/
div1 = document.getElementById('div1');
console.log(div1.getAttribute("onclick"));
    }

      </script> 
   </head> 
   <body> 
      <div id="div1" onclick="myfun();">  
      </div>
   </body>
</html>

Related Tutorials