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') // result: NodeList(3)
list.length // result: 3
list[0] // result: Text "foo "
list[1] // result: Element "<p>bar</p>"
list[2] // result: Text " baz"
Whitespace trimming
Before parsing, whitespace will be trimmed from the beginning and end of the string.
This prevents the creation of all-whitespace Text nodes at the edges of the list:
let list = up.element.createNodesFromHTML(' <p>bar</p> ') // result: NodeList(1)
list.length // result: 1
No changes will be made to whitespace in the middle of the given string.
Parameters
html
required
A string of HTML to parse.
Type: string