我使用jQuery瞄准一个div,并在我的CSS我有一个预防:徘徊
div.right-sm:hover{background-color: blue}
我想使用jQuery停止悬停:
$(this).parent('div').removeClass('right-sm:hover');
但不似乎工作?
我使用jQuery瞄准一个div,并在我的CSS我有一个预防:徘徊
div.right-sm:hover{background-color: blue}
我想使用jQuery停止悬停:
$(this).parent('div').removeClass('right-sm:hover');
但不似乎工作?
removeClass
用于从元素(即,从其class
属性)中移除CSS类,而不是用于移除所应用的样式选择器。
您需要做的是通过将内联样式应用于目标来覆盖应用的样式。例如:
$(this).parent('div').css('background-color', 'transparent');
或者只是删除right-sm
类。
假设你有一个div <div class="right-sm"></div>
你会想要做的就是删除类。正确的sm是。代码如下:
$(this).parent('div').removeClass('right-sm');
你不能只是删除规则,你必须删除整个right-sm
类。
部分:hover
不是类的一部分。班级是right-sm
。
您需要从div中删除right-sm
。
$(this).parent('div').removeClass('right-sm');
如果在right-sm
类更多的CSS,添加其他类只悬停设置和删除类。
为什么不创建类似.no-hover
的类风格并添加jQuery?这可能包括:
.no-hover:hover
{
cursor: default;
color: #000;
}
此外,如果有人可以格式化这个答案对我来说,非常感谢(目前在iPhone上)。 – Marty 2012-02-16 21:17:11
好像这个问题的重复:http://stackoverflow.com/questions/436629/how-do-i-remove-hover – derekaug 2012-02-16 21:13:57