tibewww tibewww - 2 months ago 11
jQuery Question

On hover function, do that, if X has class, do this

I have a function, which on hover, adds a class to an element.

I would like this to happen only if another div has a specific class.

So Far, I'm trying this without any result:

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

function(){


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

},

function(){
if($('.wmg-container3').hasClass('open')){
$(this).removeClass('title-hover'),
}
}
)


As you can see, I'd like the class
title-hover
to be added, but if the
wmg-container3
has the class
open
, this class should be removed .

( all this on hover the class title-overlay)

Thanks for all your help guys !

Answer

Something like this ?

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

   if($('.wmg-container3').hasClass('open')){
      $(this).removeClass('title-hover')
   }else{
      $(this).addClass('title-hover')
   } 
})