• Assigns the dataset key/value pairs to the target.

    Type Parameters

    • TN extends TagName = "*"

      Tag name of the Element representation of target.

    Parameters

    • target: null | Target<TN>

      Element, EventTarget, or CSS selector.

    • dataset: Dataset

      Object with keys of dataset attribute/property names and values of corresponding values.

    Returns ElementOf<TN>

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

    HTML (Before)

    <div
    id="example"
    data-is-active="false"
    data-count="30"
    data-label="Example"
    >
    ...
    </div>

    Using Attribute Names (data-*)

    const element = findElement("#example")!;

    setDatasetEntries(element, {
    "data-is-active", true,
    "data-count": 50,
    "data-label": "Update",
    });

    Using Property Names (camelCase)

    const element = findElement("#example")!;

    setDatasetEntries(element, {
    isActive, true,
    count: 50,
    label: "Update",
    });

    HTML (After)

    <div
    id="example"
    data-is-active="true"
    data-count="50"
    data-label="Update"
    >
    ...
    </div>