.setHtml(content)
Available on: InDom, InDomArraySets the innerHTML of the underlying element(s).Parameters:
setHtml inserts raw HTML. Use it with trusted strings; sanitize any user-provided content before calling it.Examples:
content {string} - Content to insert (coerced to string)
Returns: {InDom | InDomArray} - this for chainingThrows: Error - If the underlying element(s) has been removed
Note: setHtml inserts raw HTML. Use it with trusted strings; sanitize any user-provided content before calling it.Examples:
const div1 = $1('.example>div');
//set onClick on the every span child of div1
$a('>span', div1).onClick(n => console.log('clicked', n));
//replace innerHTML → old spans gone, listener gone
div1.setHtml('<span>another test</span>');
// re-register on the new span(s):
$a('>span', div1).onClick(n => console.log('clicked', n));
// or:
div1.onClick((_, e) => {
const span = $n(e.target).getSelfOrParent('.example>div>span');
if (span) {
console.log('clicked', span);
}
});Next: getHtml »