I search for the whole stackoverflow but I didn't get any good result against this issues.Correct me if i'm wrong.
I want to addEventListener to object that exists or haven't exists in DOM.
In Jquery we can simply do the code below:
$('document').on('click', '.my-button', function () {
alert("work!!!");
});
But how can I use only Javascript to acheive it? Below is my source code. But after the page loaded, all the new added object doesn't attach a click event.
var Button = document.getElementsByClassName("my-button");
for(i=0;i<Button.length;i++){
document.getElementsByClassName("my-button")[i].addEventListener("click",function(){
alert("Work!!!!");
});
}
Apperciate any suggestion.