SVGUseElement: href-Eigenschaft
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
Die schreibgeschützte href
-Eigenschaft der SVGUseElement
-Schnittstelle spiegelt das href
- oder xlink:href
-
Veraltet
-Attribut des angegebenen Elements wider.
Wert
Ein SVGAnimatedString
-Objekt.
Beispiele
Angenommen Sie haben das folgende SVG:
html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<defs>
<circle id="circle1" cx="50" cy="50" r="40" fill="blue" />
<circle id="circle2" cx="50" cy="50" r="40" fill="red" />
</defs>
<use href="#circle1" x="50" y="50" />
<use href="#circle2" x="100" y="50" />
</svg>
Wir können das href
-Attribut der <use>
-Elemente abrufen:
js
const uses = document.querySelectorAll("use");
console.log(uses[0].href.baseVal); // output: "#circle1"
console.log(uses[1].href.baseVal); // output: "#circle2"
Spezifikationen
Specification |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGURIReference__href |
Browser-Kompatibilität
BCD tables only load in the browser