在悬停功能上,如果X有类,请执行此操作

tib*_*www 1 javascript jquery addclass removeclass

我有一个函数,在悬停时,为一个元素添加一个类.

我希望只有在另一个div具有特定类时才会发生这种情况.

到目前为止,我正在尝试这个没有任何结果:

$('.title-overlay').hover(

   function(){ 


    $(this).addClass('title-hover'),

   },

   function(){
   if($('.wmg-container3').hasClass('open')){
    $(this).removeClass('title-hover'),
 }
}
)
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我希望title-hover添加类,但如果wmg-container3有类open,则应删除此类.

(所有这些都悬​​停在类标题叠加层上)

谢谢你们的帮助!

noi*_*tse 5

像这样的东西?

$('.title-overlay').hover(function(){ 

   if($('.wmg-container3').hasClass('open')){
      $(this).removeClass('title-hover')
   }else{
      $(this).addClass('title-hover')
   } 
})
Run Code Online (Sandbox Code Playgroud)