I want to insert html code to a div using javascript, when i am doing this then my html code is running i just want html code not output.
document.getElementById("htmlcode").innerHTML = `<button>Click me</button>`
<span id="htmlcode">HTML code here</span>
2
Answers
You may replace each:
And you should surround the resulting, escaped HTML code within
<pre><code>…</code></pre>
to:In your case:
The easiest (and probably safest) way is to use
document.createTextNode
.