jQuery on() stopPropagation not working?

后端 未结 4 1349
陌清茗
陌清茗 2020-12-05 14:08

I can\'t seem to get this to stop propagating..

  $(document).ready(function(){
      $(\"body\").on(\"click\",\"img.theater\",function(event){ 
          ev         


        
4条回答
  •  清歌不尽
    2020-12-05 15:06

    In respone to your jsfiddle @Dylan

    Here: When you click the white spot it shouldn't close. jsfiddle.net/Cs8Kq - Dylan

    Change

    if ($(event.target).is('img.theater')){
    

    to

    if ($(event.target).is('.theater-container')){
    

    and it will work.

    I solved this by using console.log(event.target) in the event handler and just using the selector that got logged out when I clicked the white area you're speaking of.

    I would've commented instead, but I don't have enough SO stardust and coins.

    EDIT: Like this jsfiddle.net/heNP4/

提交回复
热议问题