Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1229 How can I write image rollovers without using the NAME attribute (HTML 4.0 validators do not like the NAME attribute within an IMG tag)?

You are here: irt.org | FAQ | JavaScript | Image | Q1229 [ previous next ]

You need to find the number of the image on the page starting from 0 and use that instead - here Logo is image number 0 and the first image to mouseover is number one:

<script language="JavaScript"><!--
function swap(img,isrc) {
   if (!document.images) return;
   document.images[img].src = isrc;
}
//--></script>

<img src="logo.gif" width=460 height=80 alt="Logo">

<a href="..." onMouseOver="swap(1,'home_on.gif');" onMouseOut="swap(1,'home_off.gif');"><img src="home_off.gif" width=40 height=30 alt="home"></a>

<a href="..." onMouseOver="swap(2,'feedback_on.gif');" onMouseOut="swap(2,'feedback_off.gif');"><img src="feedback_off.gif"
width=40 height=30 alt="feedback"></a>

Alternatively ignore the validator.

©2018 Martin Webb