Suppose the following example:
let html = `<Parent customAttr={ value }>
<Child className="container" />
</Parent>`;
let div = document.createElement('div');
div.innerHTML = html;
// or
div.insertAdjacentHTML('beforeend', html);
console.log(div);
When inserting the html
variable as innerHTML
of the div
, first letters of <Parent>
and <Child>
elements become lowercased, camelCase of the attributes are lost and { value }
becomes wrapped into double quotes.
Is it possible and how to keep everything without these changes when inserting as innerHTML
?