小提琴:http://jsfiddle.net/xrjsq6Ls/
我似乎无法让jQuery删除我指定的类,但fadeOut()将淡出预期的DOM元素。我做错了什么?
HTML:
<div class="comment_section">
<div class="comment_outter user-marked-offensive">
<div class="comment_arrows"></div>
<div class="comment_inner">
<div class="actions">
<a class="offensive simulate-link">Mark Comment As Offensive</a>
</div>
</div>
</div>
</div>
jQuery的:
var selector = ".user-marked-offensive > .comment_inner > .actions > .offensive";
$('.comment_section').on("mouseover", selector, function () {
$(this).closest('.comment_outter').removeClass('.user-marked-offensive');
//$(this).closest('.comment_outter').fadeOut();
});
答案 0 :(得分:4)
removeClass()将类名作为参数而不是类选择器
$(this).closest('.comment_outter').removeClass('user-marked-offensive');
演示:Fiddle
答案 1 :(得分:2)
您应该在.
方法
removeClass
$(this).closest('.comment_outter').removeClass('.user-marked-offensive');
到
$(this).closest('.comment_outter').removeClass('user-marked-offensive');
答案 2 :(得分:1)
使用removeClass你不需要在类的名称之前写点;)
$(this).closest('.comment_outter').removeClass('user-marked-offensive');