setAttribute
Imperative helper for setting an attribute on an element. Unwraps reactive accessors, and removes the attribute when the value is false, null or undefined.
# Signature
# Arguments
| name | type | description |
|---|---|---|
| node | Element | target element |
| name | string | attribute name (case sensitive) |
| value | string | number | boolean | signal | attribute value. A function is treated as a reactive accessor and tracked; true sets the attribute to the empty string; false / null / undefined remove the attribute. |
Returns: void
# When to use
In JSX, prefer writing attributes directly — <div id={id}/> already flows through setAttribute. Reach for the function when you are working outside JSX: building elements via document.createElement, driving a ref from an effect, writing a propsPlugin, or bridging a third-party library.