Why does a checkbox's "checked" attribute return the opposite of it's actual value on click event?
- by Kappers
I've got the following HTML
<li><input type="checkbox" /><label>This is the label!</label></li>
I bound a click event to the li, and let the click event bubble up to the li before doing anything else.
$('li').each(function(i){
var item = $(this);
var checkbox = $("input[type='checkbox']", item);
item.bind('click', function(e){
var isChecked = checkbox.is(':checked');
console.log(isChecked);
e.stopPropagation();
});
});
Starting with an unchecked checkbox, when the click event fires, isChecked returns true when I click on the checkbox, but returns false when I click on the label or li. Does anyone know why?