Event capturing jQuery

后端 未结 3 2087
故里飘歌
故里飘歌 2020-11-27 18:02

I need to capture an event instead of letting it bubble. This is what I want:


   

Fro

3条回答
  •  温柔的废话
    2020-11-27 18:56

    I'd do it like this:

    $("body").click(function (event) {
      // Do body action
    
      var target = $(event.target);
      if (target.is($("#myDiv"))) {
        // Do div action
      }
    });
    

提交回复
热议问题