jQuery on click on everything but a div and it's children

前端 未结 4 510
时光取名叫无心
时光取名叫无心 2021-01-11 18:38

I want to do something when I click anywhere, except when I click a div and it\'s children. This is what I\'ve tried so far, but it\'s not working (clicking on it\'s childr

4条回答
  •  旧巷少年郎
    2021-01-11 19:19

    I don't have enough requirement to add commend, so I need to ask my question here to @epascarello. When I made few children, A and B still affected. I am not sure I am wrong or not, but I really want to get solution.

    jQuery(document.body).on("click", ":not(#calculator, #calculator *)", function(e){ 
        console.log(this); 
        e.stopPropagation(); 
        alert('test');
    });
    

    Live Demo

提交回复
热议问题