ToggleEvent: newState property
Baseline 2024
Newly available
Since April 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The newState
read-only property of the ToggleEvent
interface is a string representing the state the element is transitioning to.
Value
A string. Possible values are "open"
(the popover is being shown) or "closed"
(the popover is being hidden).
Examples
js
const popover = document.getElementById("mypopover");
// ...
popover.addEventListener("beforetoggle", (event) => {
if (event.newState === "open") {
console.log("Popover is being shown");
} else {
console.log("Popover is being hidden");
}
});
Specifications
Specification |
---|
HTML Standard # dom-toggleevent-newstate |
Browser compatibility
BCD tables only load in the browser