Click event doesn't fire for table rows added dynamically

后端 未结 4 1654
迷失自我
迷失自我 2021-02-12 20:16

I have an empty table to which I\'m adding rows via jQuery using:

$(\'#table > tbody:last\').append(\'\' + s         


        
4条回答
  •  广开言路
    2021-02-12 20:44

    You add rows dynamically after you have bound the event to the existing ones. You may use delegated event approach to fix the problem:

    $("#table").on("click", "tr", function(e) {
        alert(this.id);
    });
    

提交回复
热议问题