Reputation: 1320
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
Upvotes: 1
Views: 7083
Reputation: 8770
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>
Upvotes: 1
Reputation: 31961
What is your code trying to achieve? In both cases you do:
p
elementp
element to sub
(which I assume is an element itself as well)outerHTML
of the p
element to some text.You could just as well have done:
append that to sub
's childnodes:
sub.appendChild(document.createTextNode("Update Complete!"));
Or, if sub
is empty anyway, simply do:
sub.innerHTML = "Update Complete!";
Upvotes: 0