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

peq42
  • 346
  • 4
  • 18

2 Answers2

1

You should use textContent property:

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

for more information give a look on MDN

TheGr8_Nik
  • 3,080
  • 4
  • 18
  • 33
1

Use textContent instead to inject strings like this:

document.getElementById('content').textContent=txt
AndrewL64
  • 15,794
  • 8
  • 47
  • 79