---
name: "up.element.createFromHTML"
area: "API"
kind: "JavaScript function"
parent: "up.element module"
url: "https://unpoly.com/api/up.element.createFromHTML"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.element module](https://unpoly.com/api/up.element.md)</nav>

# up.element.createFromHTML(html)

Parses an element from the given HTML fragment string.

Use [`up.hello()`](https://unpoly.com/api/up.hello.md) to activate [JavaScript behavior](https://unpoly.com/api/up.script.md) within the created element.

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Example {#example}

```js
element = up.element.createFromHTML('<div class="foo"><span>text</span></div>')
element.className // returns 'foo'
element.children[0] // returns <span> element
element.children[0].textContent // returns 'text'
```

---

## Parameters {#parameters}

### html {#html}

(required)

A string of HTML from which to create the element.

The given HTML must have a single tag at its root or an error is thrown.

Type: string

---

## Return value {#return-value}

The root element of the parsed DOM tree.

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element)

