Attaching events to Checkbox Dynamically
jQuery Mobile
by limd
HTML
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
</head>
<body>
<a href="#" data-role="button" class="add">Add checkbox</a>
<div data-role="controlgroup" id="group"></div>
</body>
</html>
JavaScript
var checkbox = '<label><input type="checkbox" />Checkbox</label>';
$(document).on('click', '.add', function () {
$('#group').append(checkbox);
});
$(document).on('change', '[type=checkbox]', function (e) {
alert('clicked');
});