Get value from a data attribute - Javascript jQuery

Javascript examples for jQuery:Data Attribute

Description

Get value from a data attribute

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){//from w  ww. ja  va  2  s .c o  m
$('div').filter(function() {
  console.log($(this).attr('data-name'));
});
    });

      </script> 
   </head> 
   <body> 
      <div class="xxx" data-name="quantity" data-value="2" data-id="80"></div>  
   </body>
</html>

Related Tutorials