I am looking to create a unique effect where the color of an element changes on hover, but the hover effect is disabled while clicking on the element and the clicked element turns red. Once the element is clicked, I want to re-enable the hover effect and apply it again.
$('.divElement').on('mouseenter', function () {
$(this).addClass('red');
});
$('.divElement').on('mouseleave', function () {
$(this).removeClass('red');
});
$('.divElement').on('click', function () {
$(this).removeClass('red');
$(this).off('mouseenter mouseleave');
});
I have implemented this jQuery code to achieve the desired functionality.
<div class="divElement">Element 1</div>
<div class="divElement">Element 2</div>
<span class="divElement">Element 3</div>
<div class="divElement">Element 4</div>
.divElement {
color: blue;
}
.divElement.red {
color: red;
}