Lets say I have
<style>
#container:hover{background:red}
</style>
<div id="container"><input type="submit"></div>
When I hover on submit, #container
is still red. Can I remove that :hover on input mouseover with jquery? I do not want to change bg $('#container').css('backgroundColor','color')
, I need something like $('#container').removeAttr('hover')
.
To remove the CSS hover effect from a specific element, you can set the pointer-events property of the element (the hover behavior of which you want to disable) to “none”.
One method to do this is to add: pointer-events: none; to the element, you want to disable hover on. (Note: this also disables javascript events on that element too, click events will actually fall through to the element behind ).
Unfortunately it is impossible to manage CSS pseudo-classes with jQuery.
I'd suggest you to manipulate classes, as follows:
<style>
.red:hover{background:red}
</style>
<div id="container" class="red"><input type="submit"></div>
<script>
$("#container").removeClass("red");
</script>
You can't remove pseudo-class rules, but you can override them with event bindings:
$("#container").on('mouseover', function () {
$(this).css('background', 'blue');
}).on('mouseout', function () {
$(this).css('background', whateverItIsNormally);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With