Question

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

Was it helpful?

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>

OTHER TIPS

What is your code trying to achieve? In both cases you do:

  1. create a new p element
  2. append the p element to sub (which I assume is an element itself as well)
  3. set the outerHTML of the p element to some text.

You could just as well have done:

  1. create a new textNode with the desired text data
  2. append that to sub's childnodes:

    sub.appendChild(document.createTextNode("Update Complete!"));

Or, if sub is empty anyway, simply do:

sub.innerHTML = "Update Complete!";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top