Tag name of the Element representation of target
.
Element, EventTarget, or CSS selector.
Key or property name for the dataset entry.
Value to set for associated property or attribute name.
Element representation of the specified target
.
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 Name (data-*
)
const element = findElement("#example")!;
setDatasetEntry(element, "data-is-active", true);
setDatasetEntry(element, "data-count", 50);
setDatasetEntry(element, "data-label", "Update");
Using Property Name (camelCase)
const element = findElement("#example")!;
setDatasetEntry(element, "isActive", true);
setDatasetEntry(element, "count", 50);
setDatasetEntry(element, "label", "Update");
HTML (After)
<div
id="example"
data-is-active="true"
data-count="50"
data-label="Update"
>
...
</div>
Assigns the
value
to the dataset attribute/property namekey
in thetarget
.