.data() Method
jQuery's .data() method stores and retrieves arbitrary data on DOM elements without modifying the HTML. Data is stored in jQuery's internal cache, not in the DOM.
jQuery's .data() method stores and retrieves arbitrary data on DOM elements without modifying the HTML. Data is stored in jQuery's internal cache, not in the DOM.
// Store data
$("#userCard").data("userId", 42);
$("#userCard").data("role", "admin");
// Retrieve data
const id = $("#userCard").data("userId"); // 42
const role = $("#userCard").data("role"); // "admin"
// Remove data
$("#userCard").removeData("userId");
.data() stores any JavaScript type (objects, arrays) — not just strings like data attributes.