remove css hover style

跟風遠走 提交于 2019-12-06 19:41:34

问题


I have mark up that toggles the hover css style using this rule. When there's a checkbox inside the panel I want to remove the background image style. Is this possible? I've tried the following although it fails.

CSS:

   .StaffMode .day ul li.standard a:hover table {
        background:url("test.png"); 
    }

JS:

   $("li.test table li").hover(
        function () {
            if($(this).children(':checked')) {
              alert('need to remove the background image style');  // shows as expected
              $(this).children('a').removeClass('hover');  // this doesnt work?
            }
        }
    );

回答1:


What you need to do is put some restriction on your :hover rule, and have your JavaScript change the element so it no longer applies. Something like this:

.has-hover:hover
{
    /* do whatever */
}

And then your JavaScript does this:

$(this).children('a').removeClass('has-hover');

You can't remove the :hover but you can remove the has-hover class, and since the rule requires both, this will prevent the .has-hover:hover rule from being applied.



来源:https://stackoverflow.com/questions/12747903/remove-css-hover-style

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!