I need to isolate a variable n that is appended to end of a series of input checkboxes. ID=SubDocRecChk0, ID=SubDocRecChk1, ID=SubDocRecChk2, etc.
I want to return the n of the checkbox id that is clicked. 
But when I run this code it always returns n as 5, no matter which one I check.
  for (var n = 0; n < 5; n++) {
        $("#SubDocRecChk" + n).on("click", function () {
            if ($(this).prop('checked') == true) {
                alert(n + " is checked");
            }
            else {
                alert(n + " is unchecked");
            }
        });
    }
enter code here
Any help would be appreciated.
Other resources I've checked but haven't found my specific case. Thanks.
 
    