Search code examples
jqueryhtmlinternet-explorer-8html5shiv

Why do I get a jQuery error when using html5shiv?


The following code generates a jQuery error:

<!doctype html>
<title>jquery-test.html</title>
<script src="http://cdn.jsdelivr.net/html5shiv/3.7.0/html5shiv.js"></script>
<header>
    <hr>
</header>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>

Unknown runtime error jquery-1.10.2.js, line 3489 character 3

line 3489: div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>";


Solution

  • html5shiv requires an explicit <body> tag (GitHub issue). The following works correctly:

    <!doctype html>
    <title>jquery-test.html</title>
    <script src="http://cdn.jsdelivr.net/html5shiv/3.7.0/html5shiv.js"></script>
    <body>
        <header>
            <hr>
        </header>
        <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    </body>
    

    In the simplest case you'll just get a blank screen without errors. When adding additional content like HTML or scripts, you may get obscure errors.