Shape of attributes object value to return.
Object with names
as keys and corresponding attribute values (or null
if not present).
The arcade!WithNullValues
type represents an object with values that could be null
.
elements!InvalidElementError
if the specified target
wasn't found.
HTML
<div
id="example"
role="slider"
aria-valuemax="30"
aria-label="Example"
aria-disabled="false"
>
...
</div>
Code
type Shape = {
"aria-label": string | null;
"aria-valuemax": number | null;
invalid: string | null;
};
const element = findElement("#example")!;
getAttributes<Shape>(element, [
"aria-label",
"aria-valuemax",
"invalid", // Doesn't exist, so it's `null`
]);
// { "aria-label": "Example", "aria-valuemax": 30, invalid: null }
Builds an object with the keys equal to the attribute
names
and the value equal to the corresponding attribute value in thetarget
. If the value is found it is coerced to a boolean if"true"
or"false"
, a number if numeric, or the string value if a string. If not found, the value isnull
.You will need to perform checks for whether a value is
null
in the returned object if some of the entries weren't present. See the code block below for additional details.