Skip to content
PHP Ecosystem
Explore

HasEvents

API reference › HTML Attribute › Global › HasEvents

traitUIAwesome\Html\Attribute\Global\HasEvents
Sourcesrc/Global/HasEvents.php
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.

MethodDescriptionDefined by
addEvent()Sets an on* event attribute.HasEvents
events()Sets multiple on* event attributes.HasEvents
removeEvent()Removes an on* event attribute.HasEvents
public function addEvent(string|UnitEnum $key, Closure(): mixed|string|Stringable|UnitEnum|null $value): static

Sets an on* event attribute.

Parameters

ParameterTypeDescription
$keystring|UnitEnumEvent attribute key with or without the leading on prefix.
$valueClosure(): mixed|string|Stringable|UnitEnum|nullJavaScript handler code, or null to remove the attribute.

Returns

static: New instance with the updated on* event attribute.

Throws

public function events(mixed[] $values): static

Sets multiple on* event attributes.

Parameters

ParameterTypeDescription
$valuesmixed[]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

public function removeEvent(string|UnitEnum $key): static

Removes an on* event attribute.

Parameters

ParameterTypeDescription
$keystring|UnitEnumEvent name or enum case to remove.

Returns

static: New instance with the specified on* event attribute removed.

Throws