I need a div
to have a style when you pass the cursor over ( hover
), and another style when you do a click
.
//HTML
<div>texto</div>
//HOVER JS
$('div').hover(function() {
$(this).css({'background-color':'black', 'color:white'})
}, function () {
$(this).css({'background-color':'white', 'color:black'})
})
//CLICK JS
$('div').click(function() {
$(this).css({'background-color:red', 'color:yellow'})
})
At the beginning it works well. When I move the cursor over the div, the background of it becomes black and the letters white; when I remove the cursor, the background returns to white (or transparent) and the letters to black. Then, when I click on the div, the bottom of it turns red and its letters yellow, but here the problem! ..
At the moment of removing the cursor from my red div, the background of this one is painted white and the letters of black .. That is to say, the hover has a tail, and its effect weighs more than the effect of the click .. it is understood? I would like that when I click on the div, it will stay in red, canceling the previous effect of the hover. That is, the hover works only until it clicks. I want that.