Get data attribute with data() function - Javascript jQuery

Javascript examples for jQuery:Data Attribute

Description

Get data attribute with data() function

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(){/*ww  w.  ja  va  2  s  .  c o m*/
var current_form = $('#test')
var TEXT_EXACT = $(current_form).find('input').data('option');
console.log(TEXT_EXACT)
    });

      </script> 
 </head> 
 <body> 
  <form id="test"> 
   <input data-option="['x','y','z']"> 
  </form>  
 </body>
</html>

Related Tutorials