tsuite
    Preparing search index...

    Function createNode

    • Creates a new DOM node of the specified tag name, applies the given attributes, and appends any provided child nodes.

      Type Parameters

      • TagName extends keyof HTMLElementTagNameMap

        The tag name of the HTML element to create.

      Parameters

      • tagName: TagName

        The tag name of the element to create (e.g., 'div', 'span').

      • Optionalattributes: ElementAttributes<TagName>

        Optional attributes and styles to set on the element.

        • All standard element properties are supported.
        • The style attribute can be:
          • a CSS-in-JS object (from csstype), e.g. { color: "red", fontWeight: "bold" }
            • This provides autocomplete and strict type checking.
          • a string (as in standard DOM usage), e.g. "color: red; font-weight: bold;"
            • This does not provide autocomplete or type checking.
      • ...children: Node[]

        Child nodes to append to the created element.

      Returns HTMLElementTagNameMap[TagName]

      The created HTML element.

      // Using a CSS-in-JS object for style (type-safe, with autocomplete)
      const el1 = createNode("div", {
      textContent: "Hello!",
      style: { color: "red", fontWeight: "bold" }
      });

      // Using a string for style (no type safety or autocomplete)
      const el2 = createNode("div", {
      textContent: "World!",
      style: "color: blue; font-weight: bold;"
      });

      document.body.append(el1, el2);