HTMLButtonElement: interestForElement property

The interestForElement property of the HTMLButtonElement interface returns a reference to the interest invoker target element, in cases where the associated <button> 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 <button> element has no interest invoker target.

Examples

Basic interestForElement usage

In this example, we use a <button> element's interestForElement property to retrieve its target element's tagName. The tagName is then printed into the <button> element's text content.

HTML

We set up a relationship between the <button> element interest invoker and its target — a <div> element — by setting the <button> 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.

html
<button href="#" interestfor="mypopover">a button</button>
<div id="mypopover" popover>I am a <code>&lt;div&gt;</code> element.</div>

JavaScript

We grab a reference to the <button> element in script, then set its text content equal to a string containing the target element's tagName, retrieved via invoker.interestForElement.tagName.

js
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 button (for example, by hovering or focusing it) to make the <div> appear.

Specifications

This feature does not appear to be defined in any specification.

Browser compatibility

See also