HTML <button> commandfor Attribute
Example
Open and close a dialog with HTML only, using the
commandfor and command attributes on the
<button> element:
<button commandfor="myDialog" command="show-modal">Open dialog</button>
<dialog id="myDialog">
<p>Hello! No JavaScript needed.</p>
<button commandfor="myDialog" command="close">Close</button>
</dialog>
Try it Yourself »
Definition and Usage
The commandfor attribute turns the button into a command button.
Browser Support
The numbers in the table specify the first browser version that fully supports the attribute.
| Attribute | |||||
|---|---|---|---|---|---|
| commandfor | 135 | 135 | 144 | 26.2 | 120 |
Syntax
<button commandfor="the id of the element to control">
Attribute Values
| Value | Description |
|---|---|
| id | The id of the element to control |
❮ HTML <button> tag