|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (6 bit)
Join Date: Sep 2002
Location: Scotland
Posts: 50
|
Checking Image ID with javascript...
I'm working on a javascript which checks the image name/id before swapping the images over.
Here's a pseudo code: Cursor rolls over image Is image id = Home? Yes - change it No - Leave it Is image id= Courses? Yes - change it No - leave it and vice versa when the cursor rolls out of the image. I'm using an external stylesheet "main.js" and this is what it's written inside the file. --- example ----- function navRoll() { var inHome = "navimages/homeredAct.jpg"; var inCourses ="navimages/coursesredAct.jpg"; var inEIG = "navimages/eigredAct.jpg"; switch (this.id) { case "home": home.src = inHome; break; case "eig": eig.src = inEIG; break; } } function navOut() { var outHome = "navimages/homeDea.jpg"; var outCourses ="navimages/coursesDea.jpg"; var outEIG = "navimages/eigDea.jpg"; switch (this.id) { case "home": home.src = outHome; break; case "eig": eig.src = outEIG; break; } } -- end example --- In the HTML the images are identified by their "ids" and "names". e.g. <img id="home" name="home" src="navimages/homeredAct.jpg" border="0" title="Home" alt="Home" onMouseOver="navRoll()" onMouseOut="navOut()"> How do I compare the image's id/name so that I can exchange it for another image? Is the "this.id" reference correct? I've tried img.id element.id document.img.id document.element.id but nothing seems to work. I'm using IE 5.5. The reference to the Javascript file is <script src="main.js" type="text/javascript"></script> It is below the start of body tag. Can you please help me out? I do not know what is the correct DOM reference to a Image id. Cheers, Jova Last edited by Jova; 04-11-2003 at 10:07 AM. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|