Showing posts with label Data. Show all posts
Showing posts with label Data. Show all posts

Thursday, August 20, 2009

Element Data in jQuery

Added in jQuery 1.2
Attaching data to elements can be hazardous.
Store data: jQuery.data(elem, "name", "value");
Read data: jQuery.data(elem, "name");
All data is stored in a central cache and completely garbage collected,
as necessary.

Added in jQuery 1.2.3
Can handle namespacing:


$("div").data("test", "original");
$("div").data("test.plugin", "new data");
$("div").data("test") == "original"; // true
$("div").data("test.plugin") == "new data"; // true

Advanced data handling can be overridden by plugins:

$(element).bind("setData.draggable", function(event, key, value) {
self.options[key] = value;
}).bind("getData.draggable", function(event, key) {
return self.options[key];
});