Learning how JavaScript works in terms of the onload event with the objects on the page and the order they are written
Things learned (from my observations):
onload event written twice on the page, it seems that only one of them will take place.onload event. (onload=controlDiv1;).This example takes parts from the three process pages to show another way that both scripts can execute correctly.
head tag.body tag, after this div was created.18 Feb 2008.
Just experimenting with location (head and body) of the script and whether the function takes arguments.
Here’s the code. Please link back here if you’re using it.
Put this JavaScript in the head tag.
function controlDiv1(){
var div1=document.getElementById("div1");
div1.style.border="5px solid #ff0000";
}
onload=controlDiv1;
Put this HTML in the body tag.
<div id='div1' >This is div one. The script that controls this border is in the <code>head</code> tag.</div>
<div id='div2' >This is div two. The script that controls this border is at the end of the <code>body</code> tag, after this div was created.</div>
Put this JavaScript in the body tag, after the above HTML.
function controlDiv2(){
var div2=document.getElementById("div2");
div2.style.border="5px solid #0000ff";
}
controlDiv2();