HTML | DOM Dialog close() Method
The DOM Dialog close() method is used to close the dialog. The Dialog element is accessed by getElementById(). It is used in HTML5.
While using this method, the user can interact with other elements on the page. It is used with Dialog show() method.
Syntax:
dialogObject.close()
Example: This example shows the working of Dialog close() Method:
<!DOCTYPE html> <html> <body> <h3> HTML | DOM Dialog close() Method</h3> <p>Click on the below buttons to show or close the dialog window.</p> <button onclick="showDialog()">Show dialog box</button> <button onclick="closeDialog()">Close dialog box</button> <dialog id="showDialog" style= "color:green"> Welcome to GeeksforGeeks</dialog> <script> var gfg = document.getElementById("showDialog"); function showDialog() { gfg.show(); } function closeDialog() { gfg.close(); } </script> </body> </html> |
Output:
Before Clicking on Button:

After Clicking on Show Button:

After Clicking on Close Button:

Supported Browsers:
- Google Chrome 37.0
- Opera 24.0
- Safari 6.0
Recommended Posts:
- HTML | DOM Dialog show() Method
- HTML | DOM Dialog showModal() Method
- HTML | DOM close() Method
- HTML | DOM Dialog Object
- HTML | DOM Dialog open Property
- HTML | dialog open Attribute
- HTML5 | <dialog> Tag
- HTML | DOM contains() Method
- HTML | DOM getAttributeNode() Method
- HTML | DOM createDocumentFragment() Method
- HTML | DOM open() Method
- HTML | DOM focus() Method
- HTML | DOM createElement() Method
- HTML | DOM getAttribute() Method
- HTML | DOM write() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



