SVGElement: dataset プロパティ

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.

datasetSVGElement インターフェイスの読み取り専用プロパティで、要素のカスタムデータ属性 (data-*) への読み書きアクセスを提供します。これは文字列のマップ (DOMStringMap) を公開し、各 data-* 属性の項目を持つ文字列の地図(DOMStringMap)を公開します。

dataset の動作に関するより詳しい情報は HTMLElement.dataset を参照して下さい。

DOMStringMap です。

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"

仕様書

Specification
HTML
# dom-dataset-dev

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
dataset

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報