Reputation: 6624
I have been trying to output raw HTML inside an editable DIV, but the <div>
gets commented out.
This is what I am trying to output (Including the ``) :
\`<div class="flexContainer">HELLO WORLD</div>\`
This is what I get instead (Please NOTE HELLO WORLD
is not wrapped inside a div) :
`HELLO WORLD`;
THE CALL
let htmlCode = `\`<div class="flexContainer">HELLO WORLD</div>\`;`;
document.getElementById(myEditableDIVInputArea_Id).innerHTML = js_beautify(<pre><code>${htmlCode}</code></pre>);
How can I get the raw HTML output?
Thank you all in advance.
Upvotes: 0
Views: 566
Reputation: 10591
You can insert them as Text instead of HTML
let htmlCode = `\`<div class="flexContainer">HELLO WORLD</div>;\``
document.getElementById('x').innerText = htmlCode;
<div id=x contenteditable="true"></div>
Upvotes: 2
Reputation: 1092
function escapeHtml(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
let htmlCode = escapeHtml('<div class="flexContainer">HELLO WORLD</div>')
document.getElementById(myEditableDIVInputArea_Id).innerHTML = js_beautify(<pre><code>${htmlCode}</code></pre>);
Upvotes: 0