Edit this page

up.element up.element.createNodesFromHTML(html)
JavaScript function

This feature is experimental. Please share your experiences so we know what to keep or change.

Parses a list of nodes from a string of HTML.

The returned list can be a mixed list of Element, Text or Comment nodes.

Example

let list = up.element.createNodesFromHTML('foo <p>bar</p> baz') // => NodeList(3)
list.length // => 3
list[0] // => Text "foo "
list[1] // => Element "<p>bar</p>"
list[3] // => Text " bar"

Whitespace trimming

Before parsing, whitespace will be trimmed from the beginning and end of the string. This prevents the creation all-whitespace Text nodes at the edges of the list:

let list = up.element.createNodesFromHTML('  <p>bar</p>  ') // => NodeList(1)
list.length // => 1

No changes will be made to whitespace in the middle of the given string.


Parameters

html string

A string of HTML to parse.

Return value

A list of Element, Text or Comment nodes.