Why is the onClick event triggered twice?

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

I have the following html:


    
&         


        
10条回答
  •  遇见更好的自我
    2021-02-05 03:18

    to stop event propagation use :stopPropagation

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

    Please note, in order events are assigned in DOM.

    DEMO

提交回复
热议问题