Get HTML element attribute from javascript - Javascript DOM

Javascript examples for DOM:Element getAttribute

Description

Get HTML element attribute from javascript

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   ww  w.  j  a  v a 2s  .co m
var spans = document.getElementsByTagName('main')[0];
var match = spans.getAttribute('data-channel-id');
console.log(match);
    }

      </script> 
   </head> 
   <body>  
      <main class="soft--top" data-channel-id="348" data-preview-mode=""></main> 
      <p id="test"> Tests </p>   
   </body>
</html>

Related Tutorials