web api interface
ToggleEvent
The ToggleEvent interface represents an event that fires when a popover element is toggled between being shown and hidden.
This is the event object for the beforetoggle and toggle events, which fire on elements as follows:
- The
beforetoggleevent fires before popover or<dialog>elements are shown or hidden. - The
toggleevent fires after popover,<dialog>, or<details>elements are shown or hidden.
Constructor
ToggleEvent()- : Creates a
ToggleEventobject.
- : Creates a
Instance properties
This interface inherits properties from its parent, Event.
newStateRead only- : A string (either
"open"or"closed"), representing the state the element is transitioning to.
- : A string (either
oldStateRead only- : A string (either
"open"or"closed"), representing the state the element is transitioning from.
- : A string (either
sourceRead only- : An
Elementobject instance representing the HTML control that initiated the toggle.
- : An
Examples
Basic example
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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.