+ 5
How will i output a source code to show on the browser screen in html or JavaScript?
2 Answers
+ 2
How do you mean? Display tags?
Like:
<div></div> but it's shown on the page and not as an element?
For that use < to make a < and > to make a > so <div></div> would be <div></div>. I hope I explained that understandably đ
+ 1
One thing you can do is, put your entire JavaScript code in
`Code here `
Then keep it as a variable
Let code = `Code`
To run it use : eval(code)
To display:
document.querySelector("#out").innerHTML = code;
Here, 'out' must be the Id of a pre tag.
Though you shouldn't use eval too often but still it is a method you can try