I have a simple javascript and a simple html -- The javascript o.js has 2 functions -- The 2 funcctions are specified in o.js -- function mouseOver() {document.b1.src ="b_blue.gif";} function mouseOut() {document.b1.src ="b_pink.gif";}
The html -- <html> <head> <script type="text/javascript src="o.js"></script> </head> <body> <img border="0" src="b_pink.gif" name="b1" onmouseOver="mouseOver()" onmouseOut="mouseOut()" /> </body> </html>
The above works fine. if I remove the onmouseOver and onmouseOut from the img line in the html file, and specify them instead in the window.onload function in o.js, like this window.onload = function() { document.b1.onmouseOver=mouseOver; document.b1.onmouseOut=mouseOut; } the image swapping stops working. Can someone explain to me why it wouldn't work?