Explanation of your results:
There is no .checked()
function for a jquery object. Therefore, when you call $(this).checked()
, it results in the following error being thrown:
TypeError: Object [object Object] has no method 'checked'.
Also, there is no checked
property for a jquery object. Therefore, the value of $(this).checked
is undefined
, which is considered falsy. (You say it always returns true, but I think that is a mistake.)
Correct way to check if a checkbox is checked:
You can use any one of the following:
if (this.checked) {
if ($(this).is(':checked')) {
if ($(this).prop('checked')) {
Which one you use is a matter of style.