Reputation: 1779
I have the following javascript function. A the top of the function, I am able to detect if a checkbox is checked using $(elem).is(':checked'). Later in the function I want to wire up an onclick event in a modal window such that it will checkmark the elem's checkbox, but this does not seem to work.
Here is the function:
function toggleProductChkBx(elem,id)
{
if ($(elem).is(':checked')) {
} else {
$('#clearProductModal').on('show', function () {
removeBtn = $(this).find('.danger');
removeBtn.click(function () { clearProduct(id) });
cancelBtn = $(this).find('.secondary');
//THIS IS THE LINE THAT IS NOT WORKING
cancelBtn.click(function () { $(elem).attr("checked", "true"); });
})
.modal({ backdrop: true });
}
}
Thanks for the help!
Upvotes: 0
Views: 1151
Reputation: 2220
Change
cancelBtn.click(function () { $(elem).attr("checked", "true"); });
To
cancelBtn.click(function () { $(elem).prop("checked", true); });
Upvotes: 4