Reputation: 402
I'm using this code to grab html stored in a string into a div with contenteditable="true" (the string works, and if I manually place the code there it also works, but I need a way to "inject" html or whatever as text in it)
document.getElementById('content').innerHTML=txt
Problem is: It's not placing the html as text inside of it, but executing like it was part of the page. Is there a way around it? I need the HTML(javascript or whatever be written in the string) to be like text...
Upvotes: 0
Views: 350
Reputation: 16301
Use textContent
instead to inject strings like this:
document.getElementById('content').textContent=txt
Upvotes: 1
Reputation: 3200
You should use textContent
property:
document.getElementById('content').textContent = txt
for more information give a look on MDN
Upvotes: 1