Javascript examples for DOM:Element getAttribute
Get HTML element attribute from javascript
<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>