Sunday, 11 August 2013

AppendChild (Javascript) and Internet Explorer

AppendChild (Javascript) and Internet Explorer

As a student and someone fairly new to web development, I'm experiencing
the following seemingly strange problem in Javascript - but only in IE
(IE9 to be precise; haven't yet tried IE10). In Firefox, the script works
without any problems.
The code is like this:
item = document.createElement('li'); alert("alert1");
message = document.createTextNode("Hallo"); alert("alert2");
item.appendChild(message); alert("alert3");
In IE, alert1 and alert2 are shown, but not alert3. In other words, IE9
chokes on the third statement above (the appendChild), and never reaches
alert3. Strange indeed.
Using Google, I've found that there are known problems with appendChild in
IE (at least in earlier versions). But none of the problems described, or
the workarounds suggested, seem to match my simple code, as cited above.
Thanks in advance for any suggestions.

No comments:

Post a Comment