I click on div with id="tube_clx".
This action appends to div with id="tube" a span with id="trash".
When I click on span with id="trash". I expect alert to pop, yet it does not.
What I'm doing wrong?
<div>
<div id="tube_clx">[click div]</div>
<div id="tube"></div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#tube_clx').on('click', function(){
$('#tube').append('<span id="trash">[click span]</span>');
});
$('#trash').on('click', function(){
alert('hi');
});
});
</script>