Ben Vinegar
Ben Vinegar

Reputation: 307

How to fix innerHTML on IE not rendering entities with HTML5 doctype?

I'm observing that when using an HTML5 doctype (<!DOCTYPE html>), assigning a string containing HTML entities to a DOM object's innerHTML does not convert/render those entities on IE8 (and probably other IE versions).

document.getElementById('some-div').innerHTML = 'Doesn&apos;t work.';

Does anybody have a solution? I've come across this: http://ajaxian.com/archives/innershiv-make-innerhtml-html5-work-in-ie, but it doesn't remedy the situation. The example I give above is of an element that's already on the DOM anyways.

Upvotes: 2

Views: 1439

Answers (1)

Marco Demaio
Marco Demaio

Reputation: 34407

It's &apos; (and it does not work even using HTML4.01 DOCTYPE). Other HTML entities like &copy; &amp; etc work perfectly both IE7 and IE8.

&apos; does not work in IE (it's not because of HTML5 DOCTYPE, it's the same with other DOCTYPE). Also here they say it does not work, use &#39; as apostrophe

Upvotes: 3

Related Questions