Store arbitrary data associated with the matched elements or return the value at the named data store for the first element.
$('div').data('role', 'admin');
// Data is stored internally.
// $('div').data('role') returns "admin"
$('div').data({ id: 123, active: true });
// $('div').data('id') returns 123
// $('div').data('active') returns true
// <div data-user='{"name":"John"}'></div>
const user = $('div').data('user');
// Returns parsed object
{ name: "John" }
| Parameter | Type | Description |
|---|---|---|
| name | string | object | The name of the data key, or an object of key-value pairs to set. |
| value | any | The value to store. If undefined, acts as a getter. |
Returns: The data value for getter, or the original SR object for setter.