Baseline 2023
Newly available
The ToggleEvent
interface represents an event notifying the user an Element's state has changed.
This is the event object for the HTMLElement
beforetoggle
and toggle
events, which fire on some elements just before and just after they transition between showing and hidden, respectively.
beforetoggle
fires on popovers and <dialog>
elementstoggle
fires on popovers, <dialog>
elements, and <details>
elementsToggleEvent()
Creates an ToggleEvent
object.
This interface inherits properties from its parent, Event
.
ToggleEvent.newState
Read only
A string (either "open"
or "closed"
), representing the state the element is transitioning to.
ToggleEvent.oldState
Read only
A string (either "open"
or "closed"
), representing the state the element is transitioning from.
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 Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3