Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop Hover effect of an item using JQUERY

Tags:

jquery

css

hover

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.

like image 531
thecodeparadox Avatar asked May 02 '11 06:05

thecodeparadox


People also ask

How do I turn off hover effect?

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”.

Does jQuery handle hover?

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.

Can a div have hover?

You can attach styles to a div by using the :hover keyword.

How do you hover an element?

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.


2 Answers

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/

like image 190
Shadow Wizard Hates Omicron Avatar answered Sep 28 '22 08:09

Shadow Wizard Hates Omicron


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

like image 35
Shakeeb Ahmed Avatar answered Sep 28 '22 07:09

Shakeeb Ahmed