setBoolAttribute
Sets or removes a presence (boolean) attribute such as disabled or hidden: the helper compiled templates call for the bool: prefix.
Sets or removes a presence (boolean) attribute such as disabled or hidden: the helper compiled
templates call for the bool: prefix. A truthy value sets the attribute to "", a falsy value
removes it; the DOM is touched only when presence changes. No URL check applies.
Import#
ts
import { setBoolAttribute } from "@shadow-js/web";
Signature#
ts
function setBoolAttribute(el: Element, name: string, value: unknown): void
Parameters#
| Name | Description |
|---|---|
el |
Target element. |
name |
Attribute name, such as disabled. It must match [A-Za-z_:][A-Za-z0-9_:.-]*. |
value |
Any value: only its truthiness is read. |
Throws#
- TypeError
INVALID_ATTRIBUTE_NAMEwhennameis not a valid attribute name.
Examples#
ts
import { setBoolAttribute } from "@shadow-js/web";
const button = document.createElement("button");
setBoolAttribute(button, "disabled", true); // disabled=""
setBoolAttribute(button, "disabled", 0); // removed