javascript - change color on hover - Stack Overflow

I have buttons and they change colors when they are hovered. But I am trying to make a button remain wi

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 badges
Add a ment  | 

2 Answers 2

Reset to default 4

Here'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

相关推荐

  • javascript - change color on hover - Stack Overflow

    I have buttons and they change colors when they are hovered. But I am trying to make a button remain wi

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信