Advanced example
by Artem
HTML
<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog -->
<!-- Simple pop-up dialog box containing a form -->
<dialog id="favDialog">
<form method="dialog">
<p><label>Favorite animal:
<select>
<option></option>
<option>Brine shrimp</option>
<option>Red panda</option>
<option>Spider monkey</option>
</select>
</label></p>
<menu>
<button>Cancel</button>
<button>Confirm</button>
</menu>
</form>
</dialog>
<menu>
<button id="updateDetails">Update details</button>
</menu>
JavaScript
(function() {
var updateButton = document.getElementById('updateDetails');
var favDialog = document.getElementById('favDialog');
// “Update details” button opens the <dialog> modally
updateButton.addEventListener('click', function() {
favDialog.showModal();
});
})();