Jquery click function is not working for dynamic elements

前端 未结 4 823
借酒劲吻你
借酒劲吻你 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 03:01

    You have to use .on() function to attach an event for dynamically created elements.

    EXAMPLE

    $(document).on('click', '#DYNAMIC_ELEMENT_ID', function(){
         // your action here
    });
    

提交回复
热议问题