切换Jquery后删除/添加hover
我有这个css:
.disable { properties } .comment_action:hover { properties }
我有这个jQuery:
//comment button index disable $("#mydiv").toggle(function() { $(this).find(".comment_action").addClass('disable'); }, function(){ $(this).find(".comment_action").removeClass('disable'); });
对我来说问题是,当我点击.comment_action时:hover不会消失或删除 。 我希望如果我点击类.comment_action:hover dissapear ,如果我再次点击,则会出现.comment_action:hover。
您需要在:hover
psuedo-selector中添加要重写的属性!important
…
因为:hover
优先,即使应用.disabled
也是如此。
另外你的javascript应该使用.comment_action
而不是comment_action
来调用find
见工作示例: http : //jsfiddle.net/TN4rh/11/
更好的解决方案是切换课程。 你要做的事情可以在一行中完成。
$("#mydiv").click(function() { $(this).find(".comment_action").toggleClass('disable'); });
演示
🙂
您告诉浏览器将hover效果添加到.comment_action
。 这是该类的所有元素将发生的事情,无论它是否具有任何其他类,如.disable
。
解决方案:将:hover属性添加到新的.enable
类。 而不仅仅是删除和添加.disable
,还可以添加和删除.enable
。
.disable { properties } .enable:hover { properties }