# Invoker Commands
Show a <dialog> modally (and more) without JavaScript!
To open a <dialog> modally by clicking a <button> you typically need an onclick handler that calls the showModal method on that <dialog>.
<button onclick="document.querySelector('#my-dialog').showModal();">Show Dialog</button>
<dialog id="my-dialog">…</dialog> With invoker commands–available from Chrome 135–buttons can now perform actions on other elements declaratively, without the need for any JavaScript.
<button commandfor="my-dialog" command="show-modal">Show Dialog</button>
<dialog id="my-dialog">…</dialog> The commandfor attribute takes an ID—similar to the for attribute—while command accepts built-in values, enabling a more portable and intuitive approach.
<dialog> and a [popover] with Invoker Commands. For browsers without support a polyfill is loaded.Currently it is possible to send commands to [popover]s and <dialog> elements, with more types of elements possibly coming in the future. The commands to send to an element are mirrored after their JavaScript counterparts:
show-popover:el.showPopover()hide-popover:el.hidePopover()toggle-popover:el.togglePopover()show-modal:dialogEl.showModal()close:dialogEl.close()
It is also possible to set up custom commands to send to elements. These custom commands are prefixed by two dashes and are handled by the toggle event.
<button commandfor="some-element" command="--show-confetti">🎉</button> document.querySelector('#some-element').addEventListener('command', (e) => {
if (e.command === "--show-confetti") {
// …
}
}); A polyfill for Invoker Commands is available.