tshtml
    Preparing search index...

    Class TemplateElement

    Represents an HTML element in the template tree. Allows for dynamic attribute and class management, child element manipulation, and rendering to HTML strings.

    TemplateElement

    import { tag } from 'tshtml';

    const el = tag('div', { id: 'main' });
    el.attr('class', 'container');
    el.appendChild('Hello World');
    el.toString(); // '<div id="main" class="container">Hello World</div>'
    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    children?: TemplateItem[]

    Optional initial child elements

    CSS classes for this element. Dynamically managed through the CssClassValue interface.

    Style attribute value. Can be a string or TemplateValue.

    tag: string

    The HTML tag name (e.g., 'div', 'span', 'h1')

    Methods

    • Fluent method that appends a child element or text to this element. If a string containing HTML is passed, it will be parsed into elements.

      Parameters

      Returns TemplateElement

      This element for method chaining

      const el = tag('div');
      el.appendChild('Hello')
      .appendChild(tag('br'))
      .appendChild('World');

      // Parse HTML string
      el.appendChild('<p>Parsed HTML</p>');
    • Fluent method that sets a single attribute on this element. Special handling: the 'class' attribute updates the class object directly.

      Parameters

      Returns TemplateElement

      This element for method chaining

      el.attr('id', 'main')
      .attr('data-value', 123)
      .attr('class', 'active selected');