Why is the onClick event triggered twice?

前端 未结 10 1240
夕颜
夕颜 2021-02-05 02:40

I have the following html:


    
&         


        
10条回答
  •  礼貌的吻别
    2021-02-05 03:09

    I was also getting a similar issue where I had to download a pdf which was downloading twice. I used jQuery's stopImmediatePropagation method.

    $( "#test1" ).on("click", function(e) {
         e.stopImmediatePropagation();
    });
    
    $('#test1').trigger('click');
    

    stopImmediatePropagation will prevent any parent handlers and also any other handlers from executing. Refer here for more details.

提交回复
热议问题