jquery: get mouse click if inside a div or not

后端 未结 6 1131
栀梦
栀梦 2020-12-29 08:46

i have this HTML page



a
b
c
d
6条回答
  •  半阙折子戏
    2020-12-29 09:12

    $("body > div").click(function() {
        if ($(this).attr("id") == "in_or_out") {
            // inside
        } else {
            // not inside
        }
    });
    

    EDIT: just learned, that there is a negate:

    $("body > div:not(#in_or_out)").click(function(e) {
        // not inside
    });
    

提交回复
热议问题