开发者

change color on hover

开发者 https://www.devze.com 2023-01-10 16:46 出处:网络
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

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.开发者_JAVA技巧


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";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号