Forum Moderators: open
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<script type="text/javascript" src="prototype-1.6.0.3.js"></script>
<script type="text/javascript">
/*<![CDATA[*/ /*>fool my syntax hi-liter*/
function myRollover(event,path) {
var elem = event.element();
elem.src = path;
}
function chgImgBackTo_1m_gif(event) {
event.element().src = 'images/1m.gif'; //combine the two lines of code from myRollover
}
//initiate the elements when the window is fully loaded (same as doing window.onload = function () {//code};)
Event.observe(window, 'load', function () {
//does not use another function, the e receives the event automatically
$('image1').observe('mouseover', function (e) { e.element().src = 'images/2m.gif'; } );
//uses another function, passing arguments to it
$('image1').observe('mouseout', function (e) { myRollover(e,'images/1m.gif'); } );
//shorter, does not use another function. The 'this' object will be the event object.
$('image2').observe('mouseover', function () { this.src = 'images/2m.gif'; } );
//using callback function which requires no parameters other than event, which is automatically sent
$('image2').observe('mouseout', chgImgBackTo_1m_gif);
});
/*]]>*/
</script>
</head>
<body>
<p><a href="#"><img src="images/1m.gif" id="image1" alt="1m.gif" /></a></p>
<p><a href="#"><img src="images/1m.gif" id="image2" alt="1m.gif" /></a></p>
</body>
</html>