peq42
peq42

Reputation: 402

Load HTML content as text into div?

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

Answers (2)

AndrewL64
AndrewL64

Reputation: 16301

Use textContent instead to inject strings like this:

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

Upvotes: 1

TheGr8_Nik
TheGr8_Nik

Reputation: 3200

You should use textContent property:

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

for more information give a look on MDN

Upvotes: 1

Related Questions