0

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!

Julian Dormon
  • 1,555
  • 4
  • 29
  • 54

2 Answers2

4

Change

cancelBtn.click(function () { $(elem).attr("checked", "true"); });

To

cancelBtn.click(function () { $(elem).prop("checked", true); });

Starx
  • 75,098
  • 44
  • 181
  • 258
Zeb Rawnsley
  • 2,170
  • 1
  • 20
  • 33
0

try this:

$(elem).attr("checked", true);
Mamuz
  • 1,700
  • 12
  • 14