jQuery .data multiple object and access it

jquery.com

this is how to use JQuery.data(), the example will  wrap the variable become to object

and how to access the data

<!DOCTYPE html>
<html>
<head>
  <style>
  div { margin:5px; background:yellow; }
  button { margin:5px; font-size:14px; }
  </style>
  <script src="jquery-1.4.2.min.js"></script>
</head>
<body>
  <div id='temp_data'>A div</div>
  <button>Get val from the div</button>
<script>
$("button").click(function(e) {

    $('#temp_data').data('001', 
              {
               '51': {'tambah':101, 'kurang':51}, 
               '52': {'tambah':102, 'kurang':52}, 
               '53': {'tambah':103, 'kurang':53} 
             });
    alert($('#temp_data').data('001')['52']['tambah']);
});

</script>

</body>
</html>

Published by

G3n1k

just to remember what i had known :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s