jQuery If DIV Doesn't Have Class “x”

后端 未结 7 2346
庸人自扰
庸人自扰 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:58

    When you are checking if an element has or does not have a class, make sure you didn't accidentally put a dot in the class name:

    $('div').hasClass('className'); $('div').hasClass('.className'); #will not work!!!!

    After a long time of staring at my code I realized I had done this. A little typo like this took me an hour to figure out what I had done wrong. Check your code!

提交回复
热议问题