Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HTMLButtonElement
  4. interestForElement

HTMLButtonElement: interestForElement property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.

TheinterestForElement property of theHTMLButtonElement interface gets or sets the target element of an interest invoker, in cases where the associated<button> element is specified as an interest invoker.

SeeCreating an interest invoker for more details.

Value

AnElement object instance, ornull if the associated<button> element does not have a target element set.

Examples

BasicinterestForElement usage

In this example, we use a<button> element'sinterestForElement property to set its target element and then retrieve the target element'stagName. ThetagName is then printed in the<button> element's text content.

HTML

We include a<button> element and a<div> element. We turn the<div> element into a popover by setting apopover attribute on it.

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

JavaScript

We get references to the<button> and<div> elements in script, then declare an interest invoker-target relationship between the<button> and the<div> by setting the<button> element'sinterestForElement property equal to a reference to the<div>. We then set the button's text content equal to a string containing the target element'stagName, retrieved viainvoker.interestForElement.tagName.

js
const invoker = document.querySelector("button");const popover = document.querySelector("div");invoker.interestForElement = popover;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

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp