data attributes
Pass small values from HTML to JavaScript.
HTML · data attributesIntermediate
<button type="button" class="buy" data-product-id="42" data-price="19.99" data-name="Notebook">Buy</button>
<script>
document.querySelector('.buy').addEventListener('click', function () {
const d = this.dataset; // d.productId, d.price, d.name
console.log(d.productId, Number(d.price), d.name);
});
</script>data-*datasetjavascriptconfiguration