Jquery click function is not working for dynamic elements

前端 未结 4 822
借酒劲吻你
借酒劲吻你 2020-12-02 01:55

I am using $.each to create the button with each array object. I also tried to give each button a specific id, so I can do click event for further coding, but n

4条回答
  •  青春惊慌失措
    2020-12-02 02:35

    That was because your DOM will be created on the fly. So you have to use delegate with jQuery:

    Bind click event on document with selected id:

    $(document).on('click', '#questlist_item_button_go'+obj.questid, function(){
         // your action here
    });
    

提交回复
热议问题