Skip to content

Commit e1a895d

Browse files
Add close button in htmldialogelement/show/index.md example (#42053)
* Add close / cancel button Example was missing cancel button. Added a close button matching the /en-US/docs/Web/API/HTMLDialogElement/close example * Update index.md * Update index.md * Update to current api conventions with live exmaple --------- Co-authored-by: Hamish Willee <[email protected]>
1 parent 39381e0 commit e1a895d

File tree

1 file changed

+15
-9
lines changed
  • files/en-us/web/api/htmldialogelement/show

1 file changed

+15
-9
lines changed

files/en-us/web/api/htmldialogelement/show/index.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ browser-compat: api.HTMLDialogElement.show
88

99
{{ APIRef("HTML DOM") }}
1010

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

1513
## Syntax
1614

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

3432
## Examples
3533

36-
The following example shows a simple button that, when clicked, opens a
37-
{{htmlelement("dialog")}} containing a form via the `show()` method. From
38-
there you can click the _Cancel_ button to close the dialog (via the
39-
{{domxref("HTMLDialogElement.close()")}} method), or submit the form via the submit
40-
button.
34+
### Basic usage
35+
36+
The following example shows a simple button that, when clicked, opens a {{htmlelement("dialog")}} containing a form via the `show()` method.
37+
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.
38+
39+
#### HTML
4140

4241
```html
4342
<!-- Simple pop-up dialog box, containing a form -->
4443
<dialog id="favDialog">
4544
<form method="dialog">
45+
<button type="button" id="cancel">X</button>
4646
<section>
4747
<p>
4848
<label for="favAnimal">Favorite animal:</label>
@@ -68,6 +68,8 @@ button.
6868
<button id="updateDetails">Update details</button>
6969
```
7070

71+
#### JavaScript
72+
7173
```js
7274
const updateButton = document.getElementById("updateDetails");
7375
const cancelButton = document.getElementById("cancel");
@@ -78,7 +80,7 @@ function openCheck(dialog) {
7880
if (dialog.open) {
7981
console.log("Dialog open");
8082
} else {
81-
console.log("Dialog closed");
83+
console.log("Dialog cancelled");
8284
}
8385
}
8486

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

100+
#### Results
101+
102+
{{EmbedLiveSample("Basic usage",100, 200)}}
103+
98104
## Specifications
99105

100106
{{Specifications}}

0 commit comments

Comments
 (0)