CommandEvent: CommandEvent() constructor
Baseline
2025
Newly available
Since December 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The CommandEvent() constructor creates a new CommandEvent object.
Syntax
new CommandEvent(type)
new CommandEvent(type, options)
Parameters
type-
A string with the name of the event. It is case-sensitive and browsers set it to
command. optionsOptional-
An object that, in addition of the properties defined in
Event(), can have the following properties:sourceOptional-
An
HTMLButtonElementrepresenting the button that was interacted with to cause this event. This can be any element but we recommend only using button as a source to avoid surprises. commandOptional-
A string containing the command for the controlled element to take. While manually instantiating a
CommandEventit is possible to use any string value, but it is recommended to use one of the built-in names or prefix with two dashes (--) to ensure forward compatibility.
Return value
A new CommandEvent object.