HTMLAnchorElement: interestForElement property
The interestForElement property of the HTMLAnchorElement interface returns a reference to the associated interest invoker target element, in cases where the associated <a> element has been 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 has no interest invoker target.
Examples
>Basic interestForElement usage
In this example, we use an <a> element's interestForElement property to retrieve its target element's tagName. The tagName is then printed into the <a> element's text content.
HTML
We set up a relationship between the <a> element interest invoker and its target — a <div> element — by setting the <a> element's interestfor attribute equal to the <div> element's id. We also turn the <div> element into a popover by setting a popover attribute on it.
<a href="#" interestfor="mypopover">a link</a>
<div id="mypopover" popover>I am a <code><div></code> element.</div>
JavaScript
We grab a reference to the <a> element in script, then set its text content equal to a string containing the target element's tagName, retrieved via invoker.interestForElement.tagName.
const invoker = document.querySelector("[interestfor]");
invoker.textContent = `My target is a ${invoker.interestForElement.tagName} element`;
Result
The example renders like this:
Try showing interest in the link (for example, by hovering or focusing it) to make the <div> appear.