Edit: Okay, I had to redo the example because the problem didn’t occur in my first example
function CheckboxClick(checkbox, check) {
this.checked = check;
checkbox.click(function (event) {
alert(this.checked);
});
}
CheckboxClick($("#checkbox"), $("#checkbox").attr("checked"));
Every time you click on that checkbox, this.checked’s value changes. What do I need to do to get it to stop changing? It’s obviously assigning by reference but I don’t know how to get the primitive value. I tried valueOf() but that didn’t work for me.
I just changed this.checked to var checked and it works.
Note: If you’re using jQuery 1.6 and above, you’ll also have to change .attr method to .prop, with the same parameters.