I've got the following HTML:
<ul id=list>
<li>
<input type=checkbox />
Item 1
</li>
<li>
<input type=checkbox />
Item 2
</li>
<li>
<input type=checkbox />
Item 3
</li>
</ul>
And corresponding JavaScript:
$('ul').bind('click', function(e) {
if (e.srcElement.tagName.toLowerCase() === 'input') {
e.srcElement.checked = true;
}
return false;
});
$('body').bind('click', function() {
alert('you should see this alert if and only if you did NOT click the list');
})
When I click a checkbox, it does not get checked. I want it to be checked when the user clicks it.
How do I make it so the checkbox is checked when the user clicks it, but
still cancel the body click event handler?
I've put up a JS fiddle as well.
Edit: I understand the code is a bit clunky, but it needs to be structured this way for the application, so solutions should stay as close to the original as possible. That being said, explanations of the observed behavior would be appreciated.