SVGElement: dataset-Eigenschaft
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.
Die dataset
schreibgeschützte Eigenschaft des SVGElement
-Interfaces bietet Lese-/Schreibzugriff auf benutzerdefinierte Datenattribute (data-*
) auf Elementen. Es stellt eine Zuordnung von Strings ([
DOMStringMap](/de/docs/Web/API/DOMStringMap)
) bereit, mit einem Eintrag für jedes data-*
-Attribut.
Für weitere Informationen über das Verhalten von dataset
, siehe HTMLElement.dataset
.
Wert
Eine DOMStringMap
.
Beispiele
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"
Spezifikationen
Specification |
---|
HTML # dom-dataset-dev |
Browser-Kompatibilität
Siehe auch
data-*
SVG-Attribute- Verwendung von Datenattributen