Get and set data attribute to element - Javascript DOM

Javascript examples for DOM:Element getAttribute

Description

Get and set data attribute to element

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() {/*  ww  w . j  a v a  2s. c  o  m*/
var ul = document.getElementById('id_name');
var data_id = ul.getAttribute('data-id');
console.log(data_id);
    });

      </script> 
   </head> 
   <body> 
      <ul class="trf noborder" data-id="6581" id="id_name"> 
      </ul>  
   </body>
</html>

Related Tutorials