Reputation: 74520
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?
Upvotes: 2
Views: 378
Reputation: 8406
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);
Upvotes: 8