Java Script and other scripting languages allow you to modularize code easily by fitting it into functions. You
define a function once, then call it many times in a variety of situations. If we wanted to feature more than one bulleted item in our list of sites to visit, it would make sense to put
the rollover code into a function.
Here's some code that illustrates how functions can be put into use in our image rollover application:
<title>Image Rollover Demonstration with Functions</title>
document.images.src = "lightbulb_on.gif"
document.images.src = "lightbulb_off.gif"
<h1>List of Ideas</h1>
<img name="bulletBulb" src="lightbulb_off.gif">
Let's visit Yahoo!
How does this work? Look at the event handlers again. They look like this now:
The code that's executed in each case consists of a call to a function. The
onMouseOver= event handler triggers the lightOn() function; the onMouseOut= event handler triggers the lightOff() function. We'll cover what functions are in our next tip.