Recommended Free Tools
Use element.dataset to read and change an element’s data-* attributes in JavaScript. Its keys use camel case, but its values remain strings: convert them yourself when your code needs numbers, booleans, or another type.
What the Dataset API does
HTML lets you add custom attributes such as data-item-id to elements. In JavaScript, HTMLElement.dataset exposes those attributes through a DOMStringMap. The dataset property itself is a read-only reference, but you can change or remove its individual entries to update the corresponding HTML attributes.
The WHATWG HTML Living Standard describes custom data attributes as intended for “custom data, state, annotations, and similar, private to the page or application,” where no more appropriate attribute or element exists. See the HTML Living Standard.
How data-* names map to dataset keys
In markup, custom attributes use lowercase, hyphen-separated names. In JavaScript, a hyphen followed by a lowercase ASCII letter is removed and that letter is capitalized: data-index-number becomes dataset.indexNumber.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
| HTML attribute | JavaScript dataset key |
|---|---|
data-index-number |
dataset.indexNumber |
data-parent |
dataset.parent |
data-user-id |
dataset.userId |
Dot notation works for ordinary camel-case keys. Bracket notation is useful when you prefer to write a key as a string: element.dataset['indexNumber']. For predictable mapping, use conventional lowercase words separated by hyphens; MDN advises avoiding non-alphabetic characters after a hyphen in names intended for dataset access. See MDN’s data-* reference.
Read, update, and remove an attribute
This example reads a value, updates an existing attribute, adds another, and removes it:
<article data-index-number="12314" data-parent="cars"></article>
const article = document.querySelector("article");
const index = Number(article.dataset.indexNumber);
article.dataset.parent = "vehicles";
article.dataset.reviewed = "true";
delete article.dataset.reviewed;
Reading article.dataset.indexNumber returns the string "12314"; Number() performs the conversion. Assigning "true" stores the string "true", not a Boolean. Likewise, assigning null stores the string "null". Use delete element.dataset.key to remove the matching data-key attribute.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Dataset values are strings, not typed data
Every dataset value is a string. Parse or validate values explicitly before using them as numbers, Boolean flags, or other types. For example, Number(element.dataset.count) converts a numeric string, but your code should still account for missing or invalid input. Do not rely on a value such as "false" behaving like the Boolean false.
For details on reflection, conversion, and deletion, see MDN’s HTMLElement.dataset reference.
Find elements using data attributes
Use a CSS attribute selector with querySelector to find one matching element, or querySelectorAll to get all matches:
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
const oneItem = document.querySelector('[data-item-id="42"]');
const allItems = document.querySelectorAll('[data-state="open"]');
You can also iterate over a collection of elements you already have. Choose based on whether you need one known match, all matching elements, or already hold the relevant nodes; the available documentation does not establish that one approach is faster.
CSS can match data attributes for styling, and attr() can use an attribute value in generated content. These values are still HTML attribute strings, not typed CSS data. See MDN’s guide to using data attributes.
When data attributes are a good fit
Use data-* for small pieces of custom information naturally associated with a particular element—for example, an item identifier or a UI variant that JavaScript or CSS needs to act on. If HTML already provides an appropriate semantic attribute or element, use that instead. For information meant to be shared among independent tools, prefer an established standard or vocabulary over a private convention.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Data attributes are less suitable for state that already belongs in JavaScript and does not need to live on an element, or for data that is not naturally associated with one. The HTML Standard also advises that a page should remain usable if custom data attributes and related CSS are ignored. Libraries used across different sites should namespace their custom attributes to reduce naming collisions.
Keep user-facing content out of data attributes
Do not use a data attribute as the only place for information people need to see or understand. Assistive technology may not expose attribute values, and search engines may not index them. Put user-facing information in document text or an appropriate semantic element instead. MDN outlines these limits in its data attributes guide.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.dataset or getAttribute and setAttribute?
Both approaches read and write the same string-valued HTML attributes. dataset is concise and uses camel-case keys; attribute methods retain the exact HTML spelling. Neither performs automatic type conversion.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
| Task | dataset | Attribute methods |
|---|---|---|
Read data-item-id |
element.dataset.itemId |
element.getAttribute('data-item-id') |
Set data-item-id |
element.dataset.itemId = value |
element.setAttribute('data-item-id', value) |
Choose whichever spelling makes the code easier to read and maintain. If you need to check whether a key is an own dataset property rather than inherited through the prototype chain, use Object.hasOwn(element.dataset, 'key'); the in operator also checks the prototype chain. MDN documents these property-checking details in its dataset reference.
Browser availability
MDN marks HTMLElement.dataset as widely available and reports support across browsers since July 2015. That summary is not a guarantee for every embedded or unusual browser environment; check current compatibility data when supporting a specific legacy target.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

