Table of Contents

<HTMLElement>.setHtml()

Parses XHTML code into a DOM structure and attaches it as child node(s) of an Element.

Usage:
HTMLElement = Element.setHtml(xhtml)
Member of:
HTMLElement
Parameter:
xhtml – any valid XHTML code (required).
Returns:
The HTMLElement it was called on, thus allowing for command chaining.
Note:
This function parses the code as XHTML, which is much stricter than HTML and may throw an error if the code is incorrect. It also means that characters like < or > must be escaped as &lt; and &gt;, unless they are used to indicate an XHTML element. If you do not need the parser function, the .appendText() and .prependText() functions are the better alternatives.

Examples

Simple example:

let foo = document.getElementById('foo');
foo.setHtml('<a href="/" target="_blank">Click</a> <strong>here</strong>!');

See also

More information