SVGAElement: href 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

SVGAElement 的只讀屬性 href 返回一個 SVGAnimatedString 物件,該物件反映了 href 屬性的值,在某些情況下,還會反映 xlink:href 已棄用 屬性的值。它指定了與連結關聯的目標 URI。

此屬性允許訪問 SVG 文件中連結的 URI。

一個 SVGAnimatedString,指示 href 屬性的值。此外,對於被定義為支援它的元素,當 href 屬性未設定時,它還會反映 xlink:href 已棄用 屬性的值。

示例

js
// Select an SVG <a> element
const svgLink = document.querySelector("a");

// Access the href property
console.log(svgLink.href.baseVal); // Logs the base URI
console.log(svgLink.href.animVal); // Logs the animated URI if applicable

// Example: Reflecting xlink:href
const deprecatedLink = document.querySelector("a");
console.log(deprecatedLink.href.baseVal); // Reflects 'xlink:href' if 'href' is not set

規範

規範
Scalable Vector Graphics (SVG) 2
# __svg__SVGURIReference__href

瀏覽器相容性

另見