# HtmlElements class
{: .no_toc }

A child-element collection on an [**HtmlElement**](/tB/Packages/tbIDE/HtmlElement.md). Reached through [**HtmlElement.ChildDomElements**](/tB/Packages/tbIDE/HtmlElement.md#childdomelements). Use [**Add**](#add) to create new children and [**Item**](#item) to look one up by ID after the fact.

```tb check_build
With myToolWindow.RootDomElement
    With .ChildDomElements.Add("header", "h1")
        .Properties.innerText = "Hello"
    End With
    With .ChildDomElements.Add("body", "div")
        .Properties.style.padding = "10px"
        With .ChildDomElements.Add("greeting", "p")
            .Properties.innerText = "World"
        End With
    End With
End With
```

* TOC
{:toc}

## Methods

### Add
{: .no_toc }

Creates a new child element under the parent [**HtmlElement**](/tB/Packages/tbIDE/HtmlElement.md) and returns the new [**HtmlElement**](/tB/Packages/tbIDE/HtmlElement.md).

Syntax: *htmlElements*.**Add**( *ElementID*, *TagName* ) **As** [**HtmlElement**](/tB/Packages/tbIDE/HtmlElement.md)

*ElementID*
: *required* A DOM `id` for the new element. **String**. Pick distinct IDs across the tool window --- they double as the key for [**Item**](#item) lookups.

*TagName*
: *required* The HTML tag name. **String**. Standard tags (`"div"`, `"span"`, `"input"`, `"h1"`, `"label"`, `"img"`, …) work as expected; the IDE additionally accepts the custom-widget tags described in [Tool-window DOM tags](/tB/Packages/tbIDE/index.md#tool-window-dom-tags) on the package overview: `"chartjs"`, `"monaco"`, `"monacoDiff"`, `"listview"`, `"virtuallistview"` and `"datasheet"`.

  An `"iframe"` shows a web page inside the tool window: set its `src` property to the page's URL, and set it again to show another. The page scrolls, and follows its own links, and a `"load"` listener hears each page load. The page is a document of its own, so keys pressed while it has the focus go to it: an addin's [keyboard shortcuts](/tB/Packages/tbIDE/KeyboardShortcuts.md) do not fire there. Its `prefers-color-scheme` is the one Windows sets for apps, not the IDE's theme, so a page that follows it can be light in a dark IDE.

```tb check_build concat_group=add-tags
With myToolWindow.RootDomElement
    ' Standard DOM tags:
    Set greeting = .ChildDomElements.Add("greeting", "h1")
    Set entry    = .ChildDomElements.Add("entryBox", "input")

    ' Custom-widget tags (see sample 11 / 12 / 13 / 14):
    Set chart      = .ChildDomElements.Add("cpuChart",  "chartjs")
    Set editor     = .ChildDomElements.Add("myEditor",  "monaco")
    Set listview   = .ChildDomElements.Add("itemsList", "listview")
    Set virtList   = .ChildDomElements.Add("bigList",   "virtuallistview")
End With
```

## Properties

### Item
{: .no_toc }

Looks up an existing child element by its ID. **DefaultMember** --- so `elements("greeting")` is equivalent to `elements.Item("greeting")`.

Syntax: *htmlElements*( *ID* ) **As** [**HtmlElement**](/tB/Packages/tbIDE/HtmlElement.md)

*ID*
: A **Variant** --- typically the **String** ID assigned at [**Add**](#add) time.
