SVGElement: dataset property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The dataset
read-only property of the SVGElement
interface provides read/write access to custom data attributes (data-*
) on elements. It exposes a map of strings (DOMStringMap
) with an entry for each data-*
attribute.
For more information on the behavior of dataset
, see HTMLElement.dataset
.
Value
A DOMStringMap
.
Examples
html
<div>
<svg viewBox="0 0 120 30" xmlns="http://www.w3.org/2000/svg">
<text x="20" y="20" id="user" data-id="1234567890" data-user="carinaanand">
Carina Anand
</text>
</svg>
</div>
js
const el = document.querySelector("#user");
console.log(el.dataset.id); // "1234567890"
Specifications
Specification |
---|
HTML # dom-dataset-dev |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
dataset |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
See also
data-*
SVG attributes- Using data attributes