/    Sign up×
Community /Pin to ProfileBookmark

More than one rollover button?

Hi this script works for one button but i can’t figure how to add more button links (i need four). Any ideas?

<script type=”text/javascript”>
function mouseOver()
{
document.getElementById(“b1″).src=”voda1.gif”
}
function mouseOut()
{
document.getElementById(“b1″).src=”voda2.gif”
}

</script>

<a href=”http://www.vodafone.co.uk” target=”_blank” onmouseover=”mouseOver()”
onmouseout=”mouseOut()”>
<img border=”0″ src=”voda1.gif” id=”b1″ /></a>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@toicontienApr 25.2009 — Try this maybe?
[CODE]function initImageSwap() {
if (!document.getElementsByTagName) {
return;
}

var imgs = document.getElementsByTagName("img");
var img = null;
var len = imgs.length;
var i = 0;

var fnOver = function () {
this.src = this.src.replace("_off.", "_over.");
};

var fnOut = function () {
this.src = this.src.replace("_over.", "_off.");
};

for (i; i < len; i++) {
img = imgs[i];

if (img.className.indexOf("swap") > -1) {
img.onmouseover = fnOver;
img.onmouseout = fnOut;
}
}

imgs = null;
img = null;
}[/CODE]


To use:
[CODE]window.onload = function () {
initImageSwap();
};[/CODE]


Then name your swapped images foo_off.xxx and foo_over.xxx.
Copy linkTweet thisAlerts:
@toicontienApr 25.2009 — And you need this on your IMG tags:
[CODE]<img ... [B]class="swap"[/B]>[/CODE]
×

Success!

Help @javascriptloser 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...