
Originally Posted by
jscheuer1
The bottom line though, the onload event of of the page should be allowed to fire before you attempt to manipulate the DOM.
Compare this:
Code:
<head>
</head>
<body>
<li style="list-style: none"></li>
<script type="text/javascript">
var divg = document.createElement("div");
divg.appendChild(document.createTextNode("CHILD APPENDED"));
document.getElementsByTagName('li')[0].appendChild(divg);
</script>
<script type="text/javascript">
// create a unique image source so that this page works with continued testing
var src = "http://www.nasa.gov/images/content/84857main_EC04-0325-23_lg.jpg?" + Number(new Date);
document.write("<img src=" + src + " height=240 width=300>");
</script>
</body>
to this:
Code:
<head>
</head>
<body>
<script type="text/javascript">
onload = function(){
var divg = document.createElement("div");
divg.appendChild(document.createTextNode("CHILD APPENDED"));
document.body.appendChild(divg);
};
</script>
<script type="text/javascript">
// create a unique image source so that this page works with continued testing
var src = "http://www.nasa.gov/images/content/84857main_EC04-0325-23_lg.jpg?" + Number(new Date);
document.write("<img src=" + src + " height=240 width=300>");
</script>
</body>
===
Arie.
Bookmarks