SHARE
Facebook X Pinterest WhatsApp

HTML Goodies: Script Tip: Week 3

Written By
thumbnail Joe Burns
Joe Burns
Jan 4, 2005

Hello, again, Tippers…

Let’s spend a little more time looking at how this basic image flip actually works its magic. Here’s the code again:

<A HREF=”http://www.cnn.com”
onMouseOver=”document.pic1.src=’menu1on.gif'”
onMouseOut=”document.pic1.src=’menu1off.gif'”>
<IMG SRC=”menu1off.gif” BORDER=0 NAME=”pic1″></a>

If you’re far enough along in your HTML knowledge, you have already noticed that the image flip is put together in the form of a hypertext link.

In the “A HREF=” statement, there are two strangely capitalized items: onMouseOver and onMouseOut. Those two JavaScript commands are what are known as “Event Handlers.”

An Event Handler is a dream for us HTML coders in that it does not require that we set it aside with its own <Script Language=”javascript”> and </Script> commands. These Event Handler commands sit right in the HTML you already know how to create. What a concept! (What was the name of the comedian who always said that? My wife and I can’t come up with it.)

onMouseOver tells the browser to do something when the mouse is passed over the item. onMouseOut, as if you didn’t already know, does something when the mouse leaves the area, no SCRIPT commands needed. These Event Handlers just sit right inside the “A HREF=” command and work from there.

You’ll notice in the code that the Event Handler is pointed at the hierarchy statement that we talked about in last week’s Script Tip. That statement is telling the browser where to find the image. Remember that?

So, you may be asking, how do two Event Handlers and two hierarchy statements sitting inside the “A HREF=” command affect the image command to post the new images when the mouse passes over? That’s a solid question, indeed!

Next Week: How The Image and Script Are Linked

    


Learn to write your own JavaScripts with the
JavaScript Goodies!

You can find many other uses for JavaScript
on your Web pages here!

Recommended for you...

The Revolutionary ES6 Rest and Spread Operators
Rob Gravelle
Aug 23, 2022
Ahead of Time (AOT) Compilation in Angular
Tariq Siddiqui
Aug 16, 2022
Converting a JavaScript Object to a String
Rob Gravelle
Aug 14, 2022
Understanding Primitive Type Coercion in JavaScript
Rob Gravelle
Jul 28, 2022
HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.