Skip to main content

Class Attribute

The $class directive is used to dynamically apply CSS classes to elements based on data properties.

Usage

~index.html
<div $class="{active: isActive, highlight: shouldHighlight}">Content</div>

How it Works

  • The framework evaluates the expressions provided in the $class directive.
  • Classes are added or removed based on the truthiness of the corresponding expressions.
  • The class list is updated reactively when the underlying data changes.

Error Handling

If an expression is invalid or a property doesn't exist, the class is typically not applied, and an error might be logged to the console.

Note

note

This directive provides a convenient way to manage dynamic classes without writing complex conditional logic in your templates.