HTMLDialogElement: show() method
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.
The show() method of the HTMLDialogElement interface displays the dialog modelessly, i.e., still allowing interaction with content outside of the dialog.
Syntax
js
show()
Parameters
None.
Return value
None (undefined).
Exceptions
InvalidStateErrorDOMException-
Thrown if the dialog is already open and modal (i.e., if the dialog has already been opened with
HTMLDialogElement.showModal()).
Examples
>Basic usage
The following example shows a simple button that, when clicked, opens a <dialog> via the show() method.
From there you can click the Close dialog button to close the dialog (via the close() method).
HTML
html
<dialog id="dialog">
<button type="button" id="close">Close dialog</button>
</dialog>
<button id="open">Open dialog</button>
JavaScript
js
const dialog = document.getElementById("dialog");
const openButton = document.getElementById("open");
const closeButton = document.getElementById("close");
// Open button opens a modeless dialog
openButton.addEventListener("click", () => {
dialog.show();
});
// Close button closes the dialog box
closeButton.addEventListener("click", () => {
dialog.close();
});
Results
Specifications
| Specification |
|---|
| HTML> # dom-dialog-show-dev> |
Browser compatibility
See also
- The HTML element implementing this interface:
<dialog>.