Case1: List is present in the html already
<ul id="list1">
<li>One</li>
<li>Two</li>
</ul>
The clicked li element is detected using
$('#list1 li').bind('click', function(){
alert($(this).html());
});
Above works fine.
Case 2:
Now if the list is added dyamically
<div id="testDiv">
</div>
var output = '<ul id="list1">' +
'<li>One</li>' +
'<li>Two</li>' +
'</ul>';
$('#testDiv').html(output);
I try to detect the clicked li element using same code
$('#list1 li').bind('click', function(){
alert($(this).html());
});
In this case, it does not detect