Search code examples
javascripthtmlinternet-explorerouterhtml

JAVASCRIPT: IE: outerHTML


Problem i encounter with outerHTML using IE Browser

if i say:

txt="Update Complete!";
msg = sub.appendChild(d.createElement("p"));
msg.outerHTML = txt;

It Works Fine:

But if i say

txt="1 Error:<ul><li>Some Error</li></ul>";
msg = sub.appendChild(d.createElement("p"));
msg.outerHTML = txt;

Gives me an error of:

Message: Unknown runtime error
Line: 389
Char: 4
Code: 0
URI: http://10.1.1.16/schedule_calendar/js/validate.js

Line:389 pertains to "msg.outerHTML = txt;"

Can anyone help me with this one.. Thanks in advance


Solution

  • For some reasons I don't know, in most cases modifying outerHTML is not allowed. I am guessing that, this is because when you are modifying the outerHTML of an element you are actually replacing the current element.

    IMO, it safer to replace a element than modifying its outerHTML.

    In your case, maybe this will suffice:

    UPDATES HERE:

    <html>
    <head><title>Test</title></head>
    <body>
    <div>
        some content...
        <div id="sub"></div>
    </div>
    <script type="text/javascript">
    window.onload = function(){
        var sub = document.getElementById('sub');
        var txt="<p>Update Complete!</p>";
        sub.innerHTML = txt;
    
        alert('test 1');
    
        txt="1 Error:<ul><li>Some Error</li></ul>";
        sub.innerHTML = txt;
    }
    </script>
    </body>
    </html>