Jquery “if this and if that” then do this

前端 未结 2 731
鱼传尺愫
鱼传尺愫 2021-02-13 05:36

This should be so simple, but it\'s not working for me. I want to say:

If this doesn\'t have the class \"current\" AND if the body class does not equal \"home\", then do

2条回答
  •  说谎
    说谎 (楼主)
    2021-02-13 06:07

    Try $("body") and &&:

       if ( (!$(this).hasClass("current")) && (!$("body").hasClass("home"))  ){
        //...
    

    Or this way , it is shorter:

       if ( !$(this).is(".current") && !$("body").is(".home")  ){
         //...
    

提交回复
热议问题