JS image rollover - only works in Firefox?

Javascript coding ..

Moderators: macek, egami, gesf

Ibiscribe
New php-forum User
New php-forum User
Posts: 1
Joined: Fri Dec 23, 2011 11:17 am
Location: The beach!
Contact:

JS image rollover - only works in Firefox?

Postby Ibiscribe » Fri Dec 23, 2011 12:19 pm

I've been playing with Javascript a bit in my spare time, trying to create a simpler image rollover. I couldn't understand why most of the scripts I see online are so long and complex. I've seen a couple shorter scripts but they didn't seem to work in any of the browsers I tried.

Although I don't know too much I was able to cook up a very simple script. It works in Firefox, but only that one browser. I get it that Explorer's a bit pickier when it comes to handling images, but isn't there some way to make a simple script like this that won't take up 20 lines just to swap out two images?

Code: Select all

<script type="text/javascript">
function rolloverimg(myid,usethisimg){document[myid].src=usethisimg;}
</script>

<a href="#" onmouseover="rolloverimg('shoppingbag','images/shoppingbag2.gif');" onmouseout="rolloverimg ('shoppingbag','images/shoppingbag.gif');"><img src="images/shoppingbag.gif" width="11" height="13" border="0" alt="Shopping Bag" id="shoppingbag" /></a>

<a href="#" onmouseover="rolloverimg('email','images/email2.gif');" onmouseout="rolloverimg ('email','images/email.gif');"><img src="images/email.gif" width="11" height="13" border="0" alt="E-mail" id="email" /></a>

Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest

cron