HTML | DOM Dialog showModal() Method

The DOM Dialog showModal() method is used to show the dialog. The Dialog element is accessed by getElementById(). It is used in HTML5.
While using this method, the user can’t interact with other elements on the page. To make user interact with other elements, use show() Method.

Syntax:

dialogObject.showModal()

Example: This example shows the working of Dialog showModal() Method:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<body>
  
<h3> HTML | DOM Dialog showModal() Method</h3>
<p>Click on the below buttons to show the dialog window.</p>
  
<button onclick="showDialog()">Show dialog box</button>
  
  
<dialog id="showDialog" style= "color:green">
            Welcome to GeeksforGeeks</dialog>
  
<script>
var gfg = document.getElementById("showDialog"); 
  
function showDialog() { 
gfg.showModal(); 
</script>
  
</body>
</html>                    
                    

chevron_right


Output:
Before Clicking on Button:

After Clicking on Button:

Supported Browsers:

  • Google Chrome 37.0
  • Opera 24.0
  • Safari 6.0


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.