SVGUseElement: thuộc tính href

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.

Thuộc tính chỉ đọc href của giao diện SVGUseElement phản ánh thuộc tính href hoặc xlink:href Đã lỗi thời của phần tử đã cho.

Giá trị

Một đối tượng SVGAnimatedString.

Ví dụ

Cho SVG sau:

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>

Chúng ta có thể truy cập thuộc tính href của các phần tử <use>:

js
const uses = document.querySelectorAll("use");
console.log(uses[0].href.baseVal); // output: "#circle1"
console.log(uses[1].href.baseVal); // output: "#circle2"

Thông số kỹ thuật

Thông số kỹ thuật
Scalable Vector Graphics (SVG) 2
# __svg__SVGURIReference__href

Tương thích trình duyệt