Store values in html data attribute - Javascript jQuery

Javascript examples for jQuery:Data Attribute

Description

Store values in html 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-3.1.1.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/* ww  w.  ja v a 2s .c om*/
var colors = $("span").data("fruits").split(" ");
console.log(colors);
    }

      </script> 
   </head> 
   <body> 
      <span data-fruits="mango apple banana"></span>  
   </body>
</html>

Related Tutorials