I have multiple buttons on a single page, and I want the hover effect to be applied to all of them with just one code using jQuery. Please review my code below.
$(document).ready(function(){
$('.button').hover(function(){
var bc=$(this).css('background-color');
var cl=$(this).css('color');
$(this).css('background-color',cl);
$(this).css('color',bc);
});
});
.button {
color: #FFFFFF;
text-align: center;
font-size: 22px;
height:70px;
width: 160px;
margin: 5px;
transition: all 0.5s;
margin-right:30px;
}
.button:hover{
transform: scale(1.1);
}
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
</head>
<body>
<button class="button" style="background-color: red;">Hover </button>
<button class="button" style="background-color: green;">Hover </button>
<button class="button" style="background-color: blue;">Hover </button>
</body>
</html>
The hover effect works well for individual buttons, but hovering continuously changes the color. Is there a way to prevent this and keep the color constant during hover?