/    Sign up×
Community /Pin to ProfileBookmark

Buttons and background

Here is what I want to do:
I have some buttons in my page, onmouseover I want it to change color and then onmouseout to return to original BUT if I click on them I want them to change to a different color and stay like that.
The button:

[CODE]
<button id=”original” onmouseover=”changeIt(this);” onmouseout=”this.style.background=””; onclick=”goToOriginal(this);”>Home</button>[/CODE]

The functions:

[CODE]function changeIt(ob){
ob.style.background=’purple’;
}
function goToOriginal(ob){
ob.detachEvent(‘onmouseover’,changeIt(ob));
ob.style.background=’red’;
}[/CODE]

Also in IE afte mouseover and mouseout the background color of my button will switch to the one the div that contains it has and will remain like that :S

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@donatelloApr 22.2009 — http://www.rainbow.arch.scriptmania.com/scripts/fade_button.html

It might not be precisely what you had in mind, but can be easily modified to do what you asked and more.

?
×

Success!

Help @salvi 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.15,
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,
)...