MDN self-hosted library · e01.org

HTMLElement: command event

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
const popover = document.getElementById("mypopover");

// …

popover.addEventListener("command", (event) => {
  if (event.command === "show-popover") {
    console.log("Popover is about to be shown");
  }
});
js
button.addEventListener("click", (event) => {
  event.preventDefault(); // the `command` event will never fire
});
js
element.addEventListener("command", (event) => {
  event.preventDefault(); // the `command` event fires but the default behavior is canceled
});