I want to have the innerHTML
of my div
element to contain some HTML code, rather than displaying the expected result of that html as the browser normally would. How do I do this using Javascript?
Asked
Active
Viewed 377 times
2

Web_Designer
- 72,308
- 93
- 206
- 262
1 Answers
8
With normal JavaScript:
var div = document.getElementById('foo');
while (div.firstChild) {
div.removeChild(div.firstChild);
}
div.appendChild(document.createTextNode(html));
With jQuery:
$('#foo').text(html);

Nathan Ostgard
- 8,258
- 2
- 27
- 19