Open your project and search for .showModal() . Now search for addEventListener next to a close button. If you've built more than two dialogs, you've probably written the same eight lines more than twice — get the dialog, open it, find the button inside it, close it.
None of those eight lines are your app's logic. They're you, manually, telling the browser what it already knows how to do.
The wiring you've written more times than you'd like to admit
Here's the pattern. It's not bad code — it's just the same code, over and over:
<button id= "open-btn" > Delete account </button> <dialog id= "confirm-dialog" > <p> This can't be undone. Are you sure? </p> <button id= "close-btn" > Cancel </button> </dialog>
Enter fullscreen mode
Exit fullscreen mode
const dialog = document . getElementById ( " confirm-dialog " ); document . getElementById ( " open-btn " ). addEventListener ( " click " , () => { dialog . showModal (); }); document . getElementById ( " close-btn " ).…