jQuery bind click *ANYTHING* but *ELEMENT*

前端 未结 6 474
死守一世寂寞
死守一世寂寞 2020-12-02 07:24

Say there are some elements floating around, and I\'m trying to do some when I click ANYTHING(divs, body, whatever...) but the one specified (e.g. div#special).

I\'m

6条回答
  •  隐瞒了意图╮
    2020-12-02 07:55

    you need to do different binds, there is no need to process all this clicks in one function

    $('body').bind('click', function(e){
      bodyClickEvent();
    });
    $('div.floating').bind('click',function(e){
      elementClickEvent(this);
      e.stopPropagation(); //prevents bodyClickEvent
    });
      $('div#special').bind('click', function(){
      e.stopPropagation(); //prevents bodyClickEvent
    });
    

提交回复
热议问题