HasEvents
API reference › HTML Attribute › Global › HasEvents
Used by 4 types
Provides an immutable API for on* event attributes.
See also: https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#event_handler_attributes.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
addEvent() | Sets an on* event attribute. | HasEvents |
events() | Sets multiple on* event attributes. | HasEvents |
removeEvent() | Removes an on* event attribute. | HasEvents |
Method details
Section titled “Method details”addEvent()
Section titled “addEvent() ”public function addEvent(string|UnitEnum $key, Closure(): mixed|string|Stringable|UnitEnum|null $value): staticSets an on* event attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string|UnitEnum | Event attribute key with or without the leading on prefix. |
$value | Closure(): mixed|Stringable|UnitEnum| | JavaScript handler code, or null to remove the attribute. |
Returns
static: New instance with the updated on* event attribute.
Throws
InvalidArgumentException: if one or more arguments are invalid, of incorrect type or format.
events()
Section titled “events() ”public function events(mixed[] $values): staticSets multiple on* event attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | mixed[] | Associative array of event keys and handlers. Values may be Stringable, Closure, string, or null to remove the attribute. |
Returns
static: New instance with the updated on* event attributes.
Throws
InvalidArgumentException: if one or more arguments are invalid, of incorrect type or format.
removeEvent()
Section titled “removeEvent() ”public function removeEvent(string|UnitEnum $key): staticRemoves an on* event attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string|UnitEnum | Event name or enum case to remove. |
Returns
static: New instance with the specified on* event attribute removed.
Throws
InvalidArgumentException: if the event key is invalid.