demo · v139

Dialog Cancel Button

Open the dialog, then click "Cancel". The button uses command="request-close" — declaratively firing the cancel event before closing. Watch the log on the right.

Are you sure you want to ship this?

The Cancel button below is a request-close invoker.

the html

<button commandfor="dlg" command="request-close">Cancel</button>
<dialog id="dlg">
  <p>Are you sure?</p>
</dialog>

see also