大网数据广告活动
Web 标准与前端开发

SVGAElement: interestForElement property

· 52CE 我爱测

The **`interestForElement`** property of the SVGAElement interface gets or sets the target element of an interest invoker, in cases where the associated a element is specified as an interest invoker.

HTML DOM

The interestForElement property of the SVGAElement interface gets or sets the target element of an interest invoker, in cases where the associated a element is specified as an interest invoker.

See Creating an interest invoker for more details.

Value

An Element object instance, or null if the associated <a> element does not have a target element set.

Examples

Basic interestForElement usage

In this example, we use an SVG <a> element's interestForElement property to set its target element and then retrieve the target element's tagName. The tagName is then included in the <a> element's text content.

HTML

The markup contains an SVG a element with a text element, and the link text is included within the <text> element. There's also an HTML <div> element. We turn the <div> element into a popover by setting the popover attribute on it.

<svg>
  <a href="#">
    <text x="90" y="20" text-anchor="middle">A link</text>
  </a>
</svg>
<div id="mypopover" popover>I am a <code>&lt;div&gt;</code> element.</div>
svg {
  width: 200px;
  height: 100px;
}

svg a text {
  fill: blue;
  text-decoration: underline;
}

JavaScript

We get references to the <a>, <text>, and <div> elements in script. We then create the interest invoker-target relationship between the <a> and the <div> by setting the <a> element's interestForElement property equal to a reference to the <div>. We then update the <text> content to display the target element's tagName, retrieved via invoker.interestForElement.tagName.

const invoker = document.querySelector("a");
const invokerText = document.querySelector("text");
const popover = document.querySelector("div");

invoker.interestForElement = popover;

invokerText.textContent = `My target is a ${invoker.interestForElement.tagName} element`;

Result

The example renders like this:

basic-interest-invoker

Try showing interest in the link (for example, by hovering or focusing it) to make the <div> appear.

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。