jQuery - Dynamically Create Button and Attach Event Handler

前端 未结 5 1062

I would like to dynamically add a button control to a table using jQuery and attach a click event handler. I tried the following, without success:

$(\"#myBut         


        
5条回答
  •  囚心锁ツ
    2020-12-13 12:52

    Quick fix. Create whole structure tr > td > button; then find button inside; attach event on it; end filtering of chain and at the and insert it into dom.

    $("#myButton").click(function () {
        var test = $('').find('button').click(function () {
            alert('hi');
        }).end();
    
        $("#nodeAttributeHeader").attr('style', 'display: table-row;');
        $("#addNodeTable tr:last").before(test);
    });
    

提交回复
热议问题