What you can do is rewrite it a bit into something like this:
function mouseOver() {
this.src = "Japanese.gif";
}
function mouseOut() {
this.src = "English.gif";
}
“this” refers to different things depending where you use it. In this case, “this” would refer to the image you are mousing over, so you can specify it’s source like that. If you wanted to use different images, you could make different images.
You could also specify a parameter in the functions, then pass the value in through your call:
I’m also a newbie looking at rollovers, and I had an example in the book I’m going thru, where the author has a rollover function setting up the mouseover and mouseout events. He showed an example where this function was called from the window.onload, and another where it was called from the body tag …<body onload=“rollover”>. He didn’t mention why he switched to the body onload, so I was wondering about the pros/cons of one way vs the other.
The window.onload=rollover; and the body onload=“rollover()” do the same thing; they assign a handler fuction to the window or body elements so that function rollover() runs on mouseover. Note that the syntax is different in these two cases. The () is not used in the window.onload case as it is being assigned, not run.
Some people like to keep as much of the script out of their HTML as they can. They will usually prefer window.onload, which is usually in the scripts stored in the head of the document. Others like to see what is going on in their page so they make the call to the handler more visible by putting it in the body tag. I prefer the second option.
Thanks DC…
yes, I believe the author mentioned it could be done in CSS; however, it’s a javascript book, so he was teaching how to do it in javascript.