- Published
- Author
- Ayush SrivastavaSystem Analyst
A modal is a popup that when appears on the screen we cannot interact with any other element on the webpage apart from the modal.
On other hand a dialog is a popup that when appears on the screen we can still interact with other element on the webpage
By default a dialog element will be hidden unless you add the
It is not advised to use the
To close a
Alternatively, if your
On other hand a dialog is a popup that when appears on the screen we can still interact with other element on the webpage
By default a dialog element will be hidden unless you add the
open attribute to your dialogCode
You can see meIt is not advised to use the
open attribute directly, though, as that only allows you to open a non-modal dialog. Instead, you should use the show() and showModal() JavaScript methods.Code
const dialog = document.querySelector("dialog")
dialog.show() // Opens a non-modal dialog
dialog.showModal() // Opens a modalTo close a
dialog element you just need to use the close() method.Alternatively, if your
dialog element is a modal you can use the Esc key to close it.Code
const dialog = document.querySelector("dialog")
dialog.close() // Closes the dialog