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,767
  • 4
  • 32
  • 58

2 Answers2

4

Change

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

To

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

Starx
  • 77,474
  • 47
  • 185
  • 261
Zeb Rawnsley
  • 2,210
  • 1
  • 21
  • 33
0

try this:

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