Attribute Binding
DOMY provides powerful attribute binding to dynamically update HTML attributes. You can use either the d-bind:
prefix or the shorthand :
syntax to bind attributes reactively.
Using d-bind:
Prefix
You can bind attributes using the d-bind:
directive, making them reactive.
Example: Binding a class dynamically
<p d-bind:class="dynamicClass">This text changes class dynamically.</p>
const dynamicClass = signal('highlight');
How it works:
- The class attribute is bound to the reactive variable
dynamicClass
. - When
dynamicClass
changes, the attribute updates automatically.
Using :
Shorthand
DOMY allows a shorthand syntax using :
instead of d-bind:
.
Example: Using :
for class binding
<p :class="dynamicClass">This text changes class dynamically.</p>
Equivalent to d-bind:class="dynamicClass"
.
Binding Other Attributes
Dynamic id
binding
<p d-bind:id="elementId">This paragraph has a dynamic ID.</p>
<p :id="elementId">This paragraph has a dynamic ID.</p>