AFAICT this should work but it doesn't. Using jQuery 1.9.0, I have the following:
<html>
<head>
<script type="text/javascript" src="js/libs/jquery-1.9.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("#area").html("<p>click me</p>");
});
$("p").on("click", function() {
alert($(this).text());
});
});
</script>
</head>
<body>
<p>some text</p>
<button>Create me</button>
<div id="area"></div>
</body>
</html>
Why does clicking on "some text" bring the alert but clicking on the generated "click me" not? I thought the whole point of .on() was to enable event handlers on dynamically generated code. According to Click event doesn't work on dynamically generated elements this should work but it doesn't. See http://jsfiddle.net/ymUYy/1/