jQuery If DIV Doesn't Have Class “x”

后端 未结 7 2329
庸人自扰
庸人自扰 2020-11-27 10:54

In jQuery I need to do an if statement to see if $this doesn\'t contain the class \'.selected\'.

$(\".thumbs\").hover(function(){

$(this).stop().fadeTo(\"no         


        
7条回答
  •  难免孤独
    2020-11-27 10:59

    How about instead of using an if inside the event, you unbind the event when the select class is applied? I'm guessing you add the class inside your code somewhere, so unbinding the event there would look like this:

    $(element).addClass( 'selected' ).unbind( 'hover' );
    

    The only downside is that if you ever remove the selected class from the element, you have to subscribe it to the hover event again.

提交回复
热议问题