JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<title>My Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="jquery.mobile-1.1.1.min.css" />
</head>
<body>
<div id="mypage" data-role="page" data-theme="a">
<div data-role="fieldcontain" id="fieldcontainid">
<fieldset data-role="controlgroup" id="fieldsetid">
<div id="sample">
<input id="checkboxsample" class="custom" type="checkbox" data-iconpos="left" name="checkboxsample">
<label id="labelsample" for="checkboxsample">Test</label>
</div>
<div id="existing"></div>
</fieldset>
</div>
</div>
</body>
</html>
JavaScript
$(function () {
$(document).on('click', 'input:checkbox', function (event) {
alert('Clicked');
event.preventDefault();
event.stopPropagation();
if ($(this).is(':checked')) {
$(this)
.prop('checked', false)
.checkboxradio("refresh");
} else {
$(this)
.prop('checked', true)
.checkboxradio("refresh");
}
$(this).checkboxradio("refresh");
});
readvalues();
});
function readvalues()
{
var existing = $('#existing');
existing.html('')
for (i=0; i<=3; i++)
{
var clonecheckbox = $("#sample").clone(false);
existing.append(clonecheckbox);
clonecheckbox.attr("id", i);
$("#"+i)
.find('.custom')
.attr("id","cb"+i)
.attr("name","cb"+i)
.end()
.find('label')
.attr("id","label"+i)
.attr("for","cb"+i);
}
}