Fired when the dialog is closed. Also available via the onclose property.
Examples
The following example shows a simple button that, when clicked, opens a <dialog> containing a form via the HTMLDialogElement.showModal() function. From there you can click the Cancel button to close the dialog (via the HTMLDialogElement.close() function), or submit the form via the submit button.
<!-- Simple pop-up dialog box, containing a form --><dialogid="favDialog"><formmethod="dialog"><section><p><labelfor="favAnimal">Favorite animal:</label><selectid="favAnimal"name="favAnimal"><option></option><option>Brine shrimp</option><option>Red panda</option><option>Spider monkey</option></select></p></section><menu><buttonid="cancel"type="reset">Cancel</button><buttontype="submit">Confirm</button></menu></form></dialog><menu><buttonid="updateDetails">Update details</button></menu><script>(function(){var updateButton = document.getElementById('updateDetails');var cancelButton = document.getElementById('cancel');var dialog = document.getElementById('favDialog');
dialog.returnValue ='favAnimal';functionopenCheck(dialog){if(dialog.open){
console.log('Dialog open');}else{
console.log('Dialog closed');}}// Update button opens a modal dialog
updateButton.addEventListener('click',function(){
dialog.showModal();openCheck(dialog);});// Form cancel button closes the dialog box
cancelButton.addEventListener('click',function(){
dialog.close('animalNotChosen');openCheck(dialog);});})();</script>