I have some div
elements and each of them have a hover
effect applied by CSS. But I don't always want this hover effect; it should only activate under specific conditions.
Now, how can I disable those hover
effects using jQuery when my conditions are satisfied? What is the code for disabling hover
? I don't have access to CSS files.
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”.
jQuery hover() MethodThe hover() method specifies two functions to run when the mouse pointer hovers over the selected elements. This method triggers both the mouseenter and mouseleave events. Note: If only one function is specified, it will be run for both the mouseenter and mouseleave events.
You can attach styles to a div by using the :hover keyword.
The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.
Just use the jQuery hover
instead of the CSS one.
E.g. instead of such CSS:
#Div1:hover { background-color: yellow; }
Have this jQuery:
$("#Div1").hover(function() {
$(this).css("background-color", "yellow");
}, function() {
$(this).css("background-color", "");
});
Same effect, and you control the JS code and can have conditions.
Live test case: http://jsfiddle.net/THXuc/
you can do this by using
<script>
$("someDiv").hover(function(event) {
//apply some conditions if yes
event.preventDefault();
else
return true;
});
</script>
Hope this will work for you....
Thanks
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