Get to know MDN better
Since April 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The popoverTargetElement property of the HTMLInputElement interface gets and sets the popover element to control via an <input> element of type="button".
It is the JavaScript equivalent of the popovertarget HTML attribute.
Establishing a relationship between a popover and its invoker button using the popoverTargetElement property has two additional useful effects:
A reference to a popover element in the DOM.
This example shows the basic use of the popover API, setting a <div> element as a popover, and then setting it as the popoverTargetElement of an <input> of type="button". The popover attribute is set to "auto", so the popover can be closed ("light-dismissed") by clicking outside the popover area.
First we define an <input> that we will use to display and hide the popover, and a <div> that will be the popover. In this case we don't set the popovertargetaction HTML attribute on the <input> or the popover attribute on the <div>, as we will be doing so programmatically.
The JavaScript code first gets a handle to the <div> and <input> elements. It then defines a function to check for popover support.
If the popover API is supported the code sets the <div> element's popover attribute to "auto" and makes it the popover target of the toggle button. We then set the popoverTargetAction of the button to "toggle". If the popover API is not supported we change the text content of the <div> element to state this, and hide the input element.
Note: A popover element is hidden by default, but if the API is not supported your element will display "as usual".
You can try out the example below. Show and hide the popover by toggling the button. The "auto" popover can also be light dismissed by selecting outside the bounds of the popover text.
| HTML # dom-popovertargetelement |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Nov 7, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.