0

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...

elpeleq42
  • 167
  • 3
  • 15

2 Answers2

0

You should use textContent property:

document.getElementById('content').textContent = txt

for more information give a look on MDN

TheGr8_Nik
  • 2,912
  • 1
  • 16
  • 31
0

Use textContent instead to inject strings like this:

document.getElementById('content').textContent=txt
AndrewL64
  • 14,922
  • 7
  • 43
  • 71