.click() fails after dom change

后端 未结 3 859
逝去的感伤
逝去的感伤 2020-12-20 21:22

I searched on web but I didn\'t find any answer since this \"problem\" is not the usual one about the difference between .on() and .click(). With jquery 2.1.3 the click func

3条回答
  •  暖寄归人
    2020-12-20 21:38

    $('#button1').click(function() {
        $('div').html("

    Hello

    "); }); $('#button2').click(function() { alert(0); //THIS DOESN'T WORK }); $(document).on("click", "#button2", function() { alert(0); //THIS WORKS! });

    This is correct code

    https://jsfiddle.net/hhe3npux/

提交回复
热议问题