Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions files/en-us/web/api/htmldialogelement/show/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ browser-compat: api.HTMLDialogElement.show

{{ APIRef("HTML DOM") }}

The **`show()`** method of the {{domxref("HTMLDialogElement")}}
interface displays the dialog modelessly, i.e., still allowing interaction with content
outside of the dialog.
The **`show()`** method of the {{domxref("HTMLDialogElement")}} interface displays the dialog modelessly, i.e., still allowing interaction with content outside of the dialog.

## Syntax

Expand All @@ -33,16 +31,18 @@ None ({{jsxref("undefined")}}).

## Examples

The following example shows a simple button that, when clicked, opens a
{{htmlelement("dialog")}} containing a form via the `show()` method. From
there you can click the _Cancel_ button to close the dialog (via the
{{domxref("HTMLDialogElement.close()")}} method), or submit the form via the submit
button.
### Basic usage

The following example shows a simple button that, when clicked, opens a {{htmlelement("dialog")}} containing a form via the `show()` method.
From there you can click the _Cancel_ button ("X") to close the dialog (via the {{domxref("HTMLDialogElement.close()")}} method), or submit the form via the submit button.

#### HTML

```html
<!-- Simple pop-up dialog box, containing a form -->
<dialog id="favDialog">
<form method="dialog">
<button type="button" id="cancel">X</button>
<section>
<p>
<label for="favAnimal">Favorite animal:</label>
Expand All @@ -68,6 +68,8 @@ button.
<button id="updateDetails">Update details</button>
```

#### JavaScript

```js
const updateButton = document.getElementById("updateDetails");
const cancelButton = document.getElementById("cancel");
Expand All @@ -78,7 +80,7 @@ function openCheck(dialog) {
if (dialog.open) {
console.log("Dialog open");
} else {
console.log("Dialog closed");
console.log("Dialog cancelled");
}
}

Expand All @@ -95,6 +97,10 @@ cancelButton.addEventListener("click", () => {
});
```

#### Results

{{EmbedLiveSample("Basic usage",100, 200)}}

## Specifications

{{Specifications}}
Expand Down