Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<dialog id="confirm" aria-labelledby="dlg-title"> <h2 id="dlg-title">Confirm Deletion</h2> <p>Are you sure you want to delete this item?</p> <button onclick="document.getElementById('confirm').close('cancel')">Cancel</button> <button onclick="document.getElementById('confirm').close('ok')">Delete</button> </dialog> <button onclick="document.getElementById('confirm').showModal()">Delete Item</button> <script> document.getElementById("confirm").addEventListener("close", function() { if (this.returnValue === "ok") deleteItem(); }); </script>
Result
Open