Example 1 — Set and Get Values
Official API pattern on document.body.
jQuery.data(document.body, "foo", 52);
jQuery.data(document.body, "bar", "test");
console.log(jQuery.data(document.body, "foo")); // 52
console.log(jQuery.data(document.body, "bar")); // "test" How It Works
- Set number.
jQuery.data(body, "foo", 52)stores52under"foo". - Set string. A second key
"bar"holds"test"on the same element. - Get. Passing only
element+keyreturns that value.

