I have buttons and they change colors when they are hovered. But I am trying to make a button remain with a changed color after being hovered until another button is hovered. I read a post and it said to use a:focus but this is an implementation that works only when clicking a button, not with mouseover thing.
Any help appreciated.
I have buttons and they change colors when they are hovered. But I am trying to make a button remain with a changed color after being hovered until another button is hovered. I read a post and it said to use a:focus but this is an implementation that works only when clicking a button, not with mouseover thing.
Any help appreciated.
Share Improve this question asked Aug 6, 2010 at 3:47 Code bugCode bug 31 silver badge2 bronze badges2 Answers
Reset to default 4Here's how to do it in jQuery:
$('.button').mouseover(function(event) { // mouseOver event on all buttons with class .button
$('.button').css({background:"green"}); // reset all buttons' color to default green
$(event.target).css({background:"red"}); // change current button color to red
});
html:
<a class="test" href="#" onmouseover="changeColor(this);">test</a>
<a class="test" href="#" onmouseover="changeColor(this);">test2</a>
js/jquery:
function changeColor(obj) {
$('.test').css({background:"none"});
obj.style.backgroundColor="green";
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745093057a4610809.html
评论列表(0条)