Skip to main content

el

Callable

  • el<T>(tag: T, props?: HTMLElement | Partial<{ style: Properties<0 | (string & {}), string & {}> } & Omit<HTMLElementTagNameMap[T], style>> | Children, ...children: Children): HTMLElementTagNameMap[T]

  • Creates a new HTML element of the specified type and with the given attributes and children nodes.

    @example
    el('div', { id: 'foo' }, 'Hello world')
    el('div', 'Hello world')
    el('div', [el('span', 'Hello'), el('span', 'world')])
    el('div', el('span', 'Hello world'))
    el('div', el('span', 'Hello'), el('span', 'world'))
    el('div', el('span', 'Hello world'), 'world')

    Type parameters

    • T: keyof HTMLElementTagNameMap

    Parameters

    • tag: T

      The type of HTML element to create.

    • optionalprops: HTMLElement | Partial<{ style: Properties<0 | (string & {}), string & {}> } & Omit<HTMLElementTagNameMap[T], style>> | Children

      The properties or children nodes to add to the element.

    • rest...children: Children

      The children nodes to add to the element.

    Returns HTMLElementTagNameMap[T]

    The newly created HTML element of the specified type.