Stop Hover effect of an item using JQUERY

27,036

Solution 1

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/

Solution 2

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

Share:
27,036
thecodeparadox
Author by

thecodeparadox

#SOreadytohelp Just love coding...

Updated on May 16, 2020

Comments

  • thecodeparadox
    thecodeparadox almost 4 years

    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.

  • thecodeparadox
    thecodeparadox about 13 years
    Thanks mate. But I have no access to CSS files.
  • ianace
    ianace about 13 years
    @abdullah, you dont neet to have access to css files, .css() appends whatever is written to your css
  • Shadow The Kid Wizard
    Shadow The Kid Wizard about 13 years
    Yep, what ian said - CSS files are not relevant for jQuery. :)