Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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)?

irt.org | Knowledge Base | JavaScript | Image | Q1229 [ previous next ]

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 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.


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.