Friday, June 8, 2012

How to "enable' HTML5 elements in IE that were inserted by AJAX call?

See the solution at the bottom of the question.

IE does not work good with unknown elements (ie. HTML5 elements), one cannot style them , or access most of their props. Their are numerous work arounds for this for example:

The problem is that this works great for static HTML that was available on page load, but when one creates HTML5 elements afterward (for example AJAX call containing them, or simply creating with JS), it will mark these newly added elements them as HTMLUnknownElement as supposed to HTMLGenericElement (in IE debugger).

Does anybody know a work around for that, so that newly added elements will be recognized/enabled by IE?

Here is a test page:

<html><head><title>TIME TEST</title>
<!--[if IE]>
<script src=""></script>
<script src="" type="text/javascript"></script>

<time>some time</time>
<script type="text/javascript">
$("time").text("WORKS GREAT");
$("body").append("<time>NEW ELEMENT</time>"); //simulates AJAX callback insertion

In IE you will see the: UPDATE , and NEW ELEMENT. In any other modern browser you will see UPDATE, and UPDATE

Source: Tips4all


  1. for all html5 issues in IE7 i use html5shiv and to accommodate the html5 elements coming back in ajax calls i use innershiv.

    these two small plugins worked for me like a charm so far.

    Praveen Gunasekara

  2. jQuery has some dark, magical ways of creating elements. Using document.createElement instead should make all the difference:

    var time = document.createElement("time");
    time.innerHTML = "WORKS GREAT";

    I do not believe you can use the .append() syntax (like .innerHTML += "") with HTML5 and IE. The problem isn't IE's ability to use or display the HTML5 elements, it's its ability to parse them. Any time you programmatically instantiate an HTML5 element, you must do it with document.createElement.

  3. note that innershiv functionality is built into jquery as of 1.7

  4. Read my blog about how to use innerShiv and jQuery for ajaxing in HTML 5 content.

  5. I too ran into trouble when fetching a bunch of HTML containing HTML5 elements from the server using AJAX. html5shiv wasn't able to save my day. My project template is based on the html5boilerplate and uses Modernizr to fix HTML5 tag behavior in IE < 9.
    After reading this thread I got a hunch and managed to get my code working.

    The problematic code injecting the freshly squeezed HTML into the DOM was:

    var wrapper = $('<div />')

    Basically what happens here is:

    create a new element
    the innerHTML of the new element is updated
    the new element with its innerHTML is appended to an existing element in the DOM

    Changing it to the following fixes my problem:

    var wrapper = $('<div />')

    What happens now is:

    create a new element
    the empty new element is appended to an existing element in the DOM
    the innerHTML of the newly appended element is updated

    Now even IE7 has no choice but to display asynchronously loaded HTML5 elements like I want it to :)

    Thanks Julio, will keep your plugin handy in case I need it in the future. But for now I am happy not to add the overhead of the extra DOM manipulations.

    Maybe this workaround works for some other people too.

  6. Just leaving this to contribute to the discussion.

    The script provided that @Gidon seems not working in IE8 (tested on two different machines). I had to remake the jQuery plugin in another way, see below:

    * Enable HTML5 Elements on the fly. IE needs to create html5 elements every time.
    * @author Gidon
    * @author Julio Vedovatto <>
    * @see
    (function ($) {
    jQuery.fn.html5Enabler = function () {
    var element = this;

    if (!$.browser.msie)
    return element;

    function() {
    if ($(element).find(this).size() > 0) {
    var el = $(document.createElement(child.tagName));

    for (var i = 0; i < child.attributes.length; i++)
    el.attr(child.attributes[i].nodeName, child.attributes[i].nodeValue);