-
Book Overview & Buying
-
Table Of Contents
jQuery 1.4 Reference Guide
By :
These methods allow us to associate arbitrary data with specific DOM elements.
Store or retrieve arbitrary data associated with the matched elements.
.data(key, value) .data(obj) .data([key])
key: A string naming the piece of data to set
value: The new data value
The jQuery object for chaining purposes.
obj: An object, of key-value pairs of data to set
The jQuery object, for chaining purposes.
key (optional): A string naming the piece of data to retrieve
The previously stored data.
The .data() method allows us to attach data of any type to DOM elements in a way that is safe from circular references and, therefore, from memory leaks. We can set several distinct values for a single element and retrieve them one at a time, or as a set.
$('body').data('foo', 52);
$('body').data('bar', 'test');
$.print...
Change the font size
Change margin width
Change background colour