Anadir, eliminar elementos de un Controlgroup / 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);
$('[type=checkbox]').checkboxradio().trigger('create');
$('#group').controlgroup().trigger('create');
});
$(document).on('change', '.ui-checkbox', function (e) {
var box = $(this);
setTimeout(function () {
box.remove();
$('#group').controlgroup().trigger('create');
}, 1);
});