I am trying to use on a dynamically added content and I'm not sure what I'm missing. I have two buttons one creates UL inside DIV. Then I click on another button to create LI inside the UL. On click on any of the LI i should get an alert message but nothing is happening!
<div id='ok'></div>
<button id='fst'>create ul</button>
<button id='snd'>create li</button>
<script>
$("#fst").click(function(){
$("#ok").html("<ul class='ul'></ul>");
});
$("#snd").click(function(){
$(".ul").html("<li class='myclass'>one</li><li class='myclass'>two</li>");
});
$("ul").on('click', 'li.myclass', function(){ alert('ok'); });`
</script>
any suggestion?
ulitself is created dynamically, that means it doesn't even exist when you tried to callonon it.