Attach event to dynamic elements in javascript

前端 未结 10 2252
一生所求
一生所求 2020-11-21 23:16

I\'m trying to insert html data dynamically to a list that is dynamically created, but when i try to attach an onclick event for the button that is dynamically created the e

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 23:32

    I have created a small library to help with this: Library source on GitHub

    
    
    

    The functionality is similar to jQuery.on().

    The library uses the Element.matches() method to test the target element against the given selector. When an event is triggered the callback is only called if the target element matches the selector given.

提交回复
热议问题