SyntaxStudy
Sign Up
jQuery Beginner 3 min read

Reading All .data() Keys

Reading All Data

Call .data() without arguments to get a plain object of all key-value pairs stored on an element.

Example
<div id="product"
  data-id="1"
  data-name="Laptop"
  data-price="999.99"
  data-in-stock="true">
</div>

<script>
const all = $("#product").data();
console.log(all);
// { id: 1, name: "Laptop", price: 999.99, inStock: true }
</script>
Pro Tip

.data() without arguments returns a reference to the cache object — do not mutate it directly.