This code seems not to work.
The text stays blue on hover, but I want it to be red instead after clicking this text.
Tried several actions, but none of them works
$('.secondary').click(function() {
$(this).unbind('mouseenter mouseleave');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style media="screen">
.secondary {
color: red;
font-weight: bold;
position: relative;
}
.secondary:hover {
color: blue;
}
</style>
<div class="secondary">
CLICK ME TO BE RED
</div>
2
Answers
You can use
mouseenter
andmouseleave
events and remove said events with aclick
event as well, like so:I would suggest adding/removing a class with your preferred styling instead of applying CSS through JavaScript, though. You can achieve that like so: