<p id="instructions">
Press "h" to toggle a help screen (select example window first).
</p>HTMLElement: togglePopover() method / notebook
HTMLElement: togglePopover() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
<div id="mypopover" popover>
<h2>Help!</h2>
<p>You can use the following commands to control the app</p>
<ul>
<li>Press <ins>C</ins> to order cheese</li>
<li>Press <ins>T</ins> to order tofu</li>
<li>Press <ins>B</ins> to order bacon</li>
</ul>
</div>const instructions = document.getElementById("instructions");
const popover = document.getElementById("mypopover");
if (!Object.hasOwn(HTMLElement.prototype, "popover")) {
popover.innerText = "";
instructions.innerText = "Popovers not supported";
}if (Object.hasOwn(HTMLElement.prototype, "popover")) {
document.addEventListener("keydown", (event) => {
if (event.key === "h") {
const popupOpened = popover.togglePopover();
// Check if popover is opened or closed on supporting browsers
if (popupOpened !== undefined) {
instructions.innerText +=
popupOpened === true ? `\nOpened` : `\nClosed`;
}
}
});
}