<!-- The data-* attributes are used to store product information.
     Each attribute represents:
     product name (data-name),
     price (data-price),
     stock (data-stock),
     and color (data-color).
-->
<div 
    id="product-12345"
    data-name="Sneakers"
    data-price="10000"
    data-stock="5"
    data-color="red">
    Sneakers
</div>

<!-- The button includes a data-product-id attribute
     that identifies the corresponding product ID.
-->
<button
    type="button"
    id="product-details"
    data-product-id="product-12345">
    View Product Details
</button>
const viewDetails = document.getElementById("product-details");

viewDetails.addEventListener("click", function() {
    const productId = this.dataset.productId;
    const product = document.getElementById(productId);

    /* Retrieves product name, price, stock, and color
       using data attributes from the product element. */
    const productName = product.dataset.name;
    const price = product.dataset.price;
    const stock = product.dataset.stock;
    const color = product.dataset.color;
    
    /* Combines the retrieved product information into a string
       and displays it in an alert dialog. */
    const msg = "Product Name: " + productName +
                "\nPrice: " + price + " KRW" +
                "\nStock: " + stock + " pcs" + 
                "\nColor: " + color;          
    alert(msg);
});
Rendered Output Click the button!
A browser alert will display the product details.
<div 
    id="product-12345"
    data-name="Sneakers"
    data-price="10000"
    data-stock="5"
    data-color="red">
    Sneakers
</div>
[data-name] { /* Targeted using a CSS attribute selector */
    padding: 1em;
    background-color: yellowgreen;
}
[data-color="red"] { /* Targeted using a CSS attribute selector */
    color: red;
}
<style>
    [data-text]::before {
        content: attr(data-text) ": ";
        font-weight: 600;
        color: red;
    }
</style>
<p data-text="Note">
    Do not store content that should be visible and accessible in data attributes!
</p>
Rendered Output