I am trying to create dynamic check box using jquery. but it shows some error Uncaught SyntaxError: Unexpected token ILLEGAL
i tried to remove all spaces from the code. but even though its showing same error.
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<style>
#container input {
display: block;
}
.new-element.active {
color: red;
}
</style>
<script>
$(document).ready(function () {
$("#createCheckBox").click(function (e) {
var lbl = prompt("Enter label", "");
if (lbl != null) {
var name = "
<div class='new-element'>
<input class='chk' type='checkbox' id='chk' name='chk' />
<label for='chk'>" + lbl + "</label>
</div>";
var result = true;
$("#holder").find("input[type=checkbox]").each(function (index, value) {
console.log('Entered here');
if ($($(value).closest("div").children()[1]).text() == lbl) {
result = false;
alert(lbl + ' already exists');
return;
}
});
if (result)
$("#holder").append(name);
}
});
$("#delete").click(function () {
$('.new-element input:checked').parent().remove();
});
});
</script>
</head>
<body>
<div id="container">
<input type="button" id="createCheckBox" value="Add CheckBox" style="" />
<input type="button" id="delete" value="Delete" style="" />
<input type="button" id="selectall" value="selectall" style="" />
</div>
<div id="holder"></div>
</body>
</html>