jQuery.data( element, key, value )Returns: Object
Description: Store arbitrary data associated with the specified element. Returns the value that was set.
version added: 1.2.3jQuery.data( element, key, value )
Note: This is a low-level method; a more convenient .data()
is also available.
The jQuery.data()
method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore free from memory leaks. jQuery ensures that the data is removed when DOM elements are removed via jQuery methods, and when the user leaves the page. We can set several distinct values for a single element and retrieve them later:
1 2 |
|
Note: this method currently does not provide cross-platform support for setting data on XML documents, as Internet Explorer does not allow data to be attached via expando properties.
Example:
Store then retrieve a value from the div element.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|