//created for this example function
function addButton(){
var button=document.createElement("button");
button.innerText="Click me!";
document.querySelector("#parent").appendChild(button);
return button;
};
//binding addButton
document.querySelector("#add").addEventListener("click",function(){
addButton();//add button
});
document.querySelector("#parent").addEventListener("click",function(e){
if (e.target.tagName=="BUTTON"){
print("Button was clicked. Delegated event listener.");
}
});
<div id="parent">
<button>
Click me!
</button>
</div>
<button id="add">
Add Click button
</button>
External resources loaded into this fiddle: