I use .on() to attach click events to several elements that appear dynamically on the page. The problem is that when I add .on to the container on the page and want to attach click events to several elements in the container, the latter overwrites the previous one.
<div id="container"> <div id="id1"></div> <div id="id1"></div> </div> <script> $('#container').on("click", "#id1", function(){}); $('#container').on("click", "#id2", function(){}); </script>
In the above example, only the click event for id2 works.
Is there any way around this?
Thanks, Ev.
evkorres
source share