Posted By

neal_grosskopf on 05/17/10


Tagged

jquery


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

neal_grosskopf
jaredwilli


jQuery's .data() Method - Store Information Inside Elements


 / Published in: jQuery
 

URL: http://www.nealgrosskopf.com/tech/thread.php?pid=69

jQuery has a built in method that allows developers to store information inside elements. Learn how to use the .data() method and view some examples of how this can be used.

  1. //Store information
  2. $("input").data("original", "$1.75");
  3. $("input").data("currency", "$1.50");
  4. $("input").data("decimal", 1.5);
  5.  
  6. //Retrieve information
  7. $("input").data("original");
  8. $("input").data("currency");
  9. $("input").data("decimal");
  10.  
  11. //Shorthand store
  12. $("input").data("numbers",{original: "$1.75", currency: "$1.50", decimal: 1.5});
  13.  
  14. //Shorthand retrieve
  15. $("input").data("numbers").original;
  16. $("input").data("numbers").currency;
  17. $("input").data("numbers").decimal;

Report this snippet  

You need to login to post a comment.