Templates and Binding

Element uses tagged template literals for creating reactive DOM elements. The html() function processes these templates and sets up automatic updates.

Basic Syntax

const [title, setTitle] = createSignal("Hello World!");

const template = html`
  <div class="container">
    <h1>${title}</h1>
    <p>Lorem ipsum dolor sit amet...</p>
  </div>
`;

Binding Types

Element supports different types of bindings:

1. Text Binding

const [text, setText] = createSignal("Lorem ipsum dolor sit amet...");
const template = html`<p>${text}</p>`;

2. Attribute Binding

const [className, setClassName] = createSignal("link-wrapper");
const [url, setUrl] = createSignal("https://github.com");

const template = html`
  <div class="${className}">
    <a href="${url}">Link</a>
  </div>
`;

3. Property Binding

Supported DOM Properties

4. Event Binding

Supported DOM Events

Built-in Components

Element provides built-in components for common patterns:

Conditional Rendering

List Rendering

Last updated