/    Sign up×
Community /Pin to ProfileBookmark

javascript rollover buttons for multiple instances

Hey

I have a page that has two buttons, repeated about 100 times. It’s for a song, to preview or download. The script I used works, but only when I have one instance of it in the file. The minute I have two, it doesn’t work. Short of creating id’s for every instant (code would be massive!) is there a way for each new instance to point to the same rollover code?

[CODE]<HEAD>
<SCRIPT language=”JavaScript”>
<!–

if (document.images)
{
pic1on= new Image(100,25);
pic1on.src=”shoes2.gif”;

pic1off= new Image(100,25);
pic1off.src=”shoes1.gif”;
}

function lightup(imgName)
{
if (document.images)
{
imgOn=eval(imgName + “on.src”);
document[imgName].src= imgOn;
}
}

function turnoff(imgName)
{
if (document.images)
{
imgOff=eval(imgName + “off.src”);
document[imgName].src= imgOff;
}
}

//–>
</SCRIPT>
</HEAD>
[/CODE]

Html looks like this:

[CODE]<A HREF=”index.html” onMouseover=”lightup(‘pic1’)” onMouseout=”turnoff(‘pic1’)”>
<IMG SRC=”../images/shoes1.gif” name=”pic1″ width=”100″ height=”25″ border=”0″></A> [/CODE]

Source/Example can be found here:
[url]http://www.pageresource.com/jscript/jhover.htm[/url]

I had this custom tailored with my images, but I’ve been going back and forth between CSS/JS to see what warrants the best result. All I want to do, is be able to change the image when you hover over it, and have 100 or more of the same button on the site.

Thanks!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@djstingauthorJun 05.2009 — Soo... any thoughts? I just wanna know how to do rollover buttons with javascript, and have more than one buton on the stage without having to repeat the code 100 times. There has to be an easier way lol
×

Success!

Help @djsting spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...