I'm looking for native JavaScript code for this example with jQuery:
$("#parent").on("click", ".child", function(){
alert("clicked");
});
What I did so far works with the elements that come with the page but not the dynamically generated ones:
var children = document.getElementById("parent").getElementsByClassName("child");
for (var i = 0, l = children.length; i < l; i++)
{
children[i].onclick = foo;
}
function foo(el)
{
alert("child clicked");
}
How can I make this code work for the dynamically generated elements?
If you are looking for the answer, here it is: https://stackoverflow.com/a/27373951/2748984