Jquery “if this and if that” then do this

前端 未结 2 730
鱼传尺愫
鱼传尺愫 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 05:42

    If body is not a variable, access it as a HTML tag: add quotes. Also, AND is && instead of || (that means OR):

    if (!$(this).hassClass("current") && !$("body").hasClass("home")) {
        $(this).find(".nav-overlay").show();
    }
    

    If body is a jQuery object you can do directly ... && !$body.hashClass(...).

提交回复
热议问题