JavaScript Beginner Dom · 1 min read

Read data-* with dataset

Start the JavaScript learning path »

❮ JavaScript Home All Tutorials ❯

How do I read data-price in JavaScript?

dataset API.

Example

Interactive preview available
JavaScript Example
const product = document.getElementById('product');
const price = product.dataset.price;
const category = product.dataset.category;
console.log(price, category);

Line-by-Line Walkthrough

data-category becomes dataset.category (camelCase).

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…