The .data () function allows you to store or retrieve arbitrary data and associate it with matched elements.
In many situations, it is easiest to store key-value pairs using data (), against the body tag.
Data Storage Example
//Store the string "bar" with the body tag, with the key "foo" $('body').data('foo', 'bar');
Data Search Example
//Retrieve the string "bar" var str = $('body').data('foo');
Link
Brian webster
source share