HTML | DOM Dialog Object
The DOM Dialog Object is used to represent the HTML <dialog> element. The Dialog element is accessed by getElementById(). It is used in HTML5.
Syntax:
document.getElementById("ID");
Where “id” is the ID assigned to the “Dialog” tag.
Example-1:
<!DOCTYPE html> <html> <head> <title>DOM dialog Object</title> <style> dialog { color: green; font-size: 30px; font-weight: bold; font-style: italic; } body { text-align: center; } </style> </head> <body> <h1>DOM Dialog Object</h1> <!-- Assigning id to dialog tag --> <dialog id="GFG">Welcome to GeeksforGeeks</dialog> <button onclick="myGeeks()" open>Submit</button> <script> function myGeeks() { // Accessing dialog tag var x = document.getElementById("GFG"); x.open = true; } </script> </body> </html> |
Output:
Before Clicking On Button:

After Clicking On Button:

Example-2: Dialog Object can be created by using the document.createElement Method.
<!DOCTYPE html> <html> <head> <title>DOM dialog Object</title> <style> dialog { color: green; font-size: 30px; font-weight: bold; font-style: italic; } body { text-align: center; } </style> </head> <body> <h1>DOM Dialog Object</h1> <button onclick="myGeeks()" open>Submit</button> <script> function myGeeks() { var gfg = document.createElement("DIALOG"); var f = document.createTextNode("Welcome to GeeksForGeeks"); gfg.setAttribute("open", "open"); gfg.appendChild(f); document.body.appendChild(gfg); } </script> </body> </html> |
Output:
Before Clicking On Button :

After Clicking On Button:

Supported Browsers: The browser supported by DOM Dialog Object are listed below:
- Google Chrome 37+
- Opera 24+
- Safari 6+
Recommended Posts:
- HTML | DOM Dialog open Property
- HTML | DOM Dialog showModal() Method
- HTML | DOM Dialog close() Method
- HTML | DOM Dialog show() Method
- HTML | dialog open Attribute
- HTML | DOM Object Object
- JQueryUI | dialog
- ES6 | Dialog Boxes
- HTML5 | <dialog> Tag
- How to create a pop-up to print dialog box using JavaScript?
- HTML | DOM DD Object
- HTML| DOM HR Object
- HTML | DOM S Object
- HTML | DOM Ul Object
- HTML | DOM dl Object
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.

