Add checkbox via Javascript
Description
The following code shows how to add checkbox via Javascript.
Example
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
src='http://code.jquery.com/jquery-1.6.2.js'></script>
<link rel="stylesheet" type="text/css"
href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css">
<script type='text/javascript'
src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){<!-- w w w. ja v a 2s . c om-->
$(document).ready(function () {
var counter = 0;
$('a').bind('click', function () {
counter++;
$('[data-role="page"]').append('<label for="checkbox-1">Checkbox ' + counter + '</label><input id="checkbox-' + counter + '" name="checkbox-'+ counter + '" type="checkbox" />').trigger('create');
});
});
});//]]>
</script>
</head>
<body>
<div data-role="page">
<div data-role="content">
<a href="#">click to add checkbox</a>
</div>
</div>
</body>
</html>