ToggleEvent - Web APIs | MDN
Constructor
ToggleEvent()-
Creates a
ToggleEventobject.
Instance properties
This interface inherits properties from its parent, Event.
ToggleEvent.newStateRead only-
A string (either
"open"or"closed"), representing the state the element is transitioning to. ToggleEvent.oldStateRead only-
A string (either
"open"or"closed"), representing the state the element is transitioning from. ToggleEvent.sourceRead only-
An
Elementobject instance representing the HTML control that initiated the toggle.
Examples
Basic example
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 # toggleevent |