HasAttributes
API reference › HTML Mixin › HasAttributes
Used by 4 types
Provides an immutable API for managing HTML attributes.
See also: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$attributes protected | mixed[] | HTML attributes array used by the implementing class. Default: []. | HasAttributes |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
addAttribute() | Adds or updates a single HTML attribute for the element. | HasAttributes |
attributes() | Adds or updates multiple HTML attributes for the element. | HasAttributes |
getAttribute() | Returns the value of a single HTML attribute. | HasAttributes |
getAttributes() | Returns the array of HTML attributes for the element. | HasAttributes |
removeAttribute() | Removes a specific HTML attribute from the element. | HasAttributes |
replaceAttributes() | Replaces all HTML attributes for the element. | HasAttributes |
Method details
Section titled “Method details”addAttribute()
Section titled “addAttribute() ”public function addAttribute(string|UnitEnum $key, mixed $value): staticAdds or updates a single HTML attribute for the element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string|UnitEnum | Attribute name. |
$value | mixed | Attribute value. Use null to remove the attribute. |
Returns
static: New instance with the updated attributes value.
attributes()
Section titled “attributes() ”public function attributes(mixed[] $values): staticAdds or updates multiple HTML attributes for the element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | mixed[] | Associative array of attribute keys and values. |
Returns
static: New instance with the updated attributes value.
getAttribute()
Section titled “getAttribute() ”public function getAttribute(string|UnitEnum $key, mixed $default = null): mixedReturns the value of a single HTML attribute.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string|UnitEnum | Attribute name. |
$default | mixed | Default value when the attribute is missing. |
Returns
mixed: Attribute value or default.
getAttributes()
Section titled “getAttributes() ”public function getAttributes(): mixed[]Returns the array of HTML attributes for the element.
Returns
mixed[]: Attributes array assigned to the element.
removeAttribute()
Section titled “removeAttribute() ”public function removeAttribute(string|UnitEnum $key): staticRemoves a specific HTML attribute from the element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string|UnitEnum | Attribute name to remove. |
Returns
static: New instance without the specified attribute value.
replaceAttributes()
Section titled “replaceAttributes() ”public function replaceAttributes(mixed[] $values): staticReplaces all HTML attributes for the element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$values | mixed[] | Associative array of attribute keys and values. |
Returns
static: New instance with the replaced attributes value.