• Sets the attributes of the target to the attributes object, where the key of the object is the attribute name and the value of the object is the attribute value.

    Type Parameters

    • TN extends TagName = "*"

      Tag name of the Element representation of target.

    Parameters

    • target: null | Target<TN>

      Element, EventTarget, or CSS selector.

    • attributes: Attributes<TN>

      Object with key of attribute name and value of attribute value.

    Returns ElementOf<TN>

    Element representation of the specified target.

    elements!InvalidElementError if the specified target wasn't found.

    HTML (Before)

    <div id="example" role="slider">
    ...
    </div>

    Code

    let element = findElement<"div">("#example")!;

    element = setAttributes(element, {
    "aria-label", "Click me",
    "aria-valuenow": 20,
    });

    HTML (After)

    <div
    id="example"
    role="slider"
    aria-label="Click me"
    aria-valuenow="20"
    >
    ...
    </div>