jQuery bind click *ANYTHING* but *ELEMENT*

前端 未结 6 481
死守一世寂寞
死守一世寂寞 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 08:04

    I once solved this a little easier than the other answers, whithout taking care that click really goes down the DOM-Tree

    just check if your element is hovered ;)

    $(document).on('click', function (e) {
    
      if($('#special:hover').length > 0){
        // on our special element
      }else{
        // not on our special element
      }
    
    });
    

    Cheers

提交回复
热议问题