I am trying to check the event.target.nodeName as follows:
$("input").click(function(e){
if(e.target.nodeName == "LABEL") {
alert('label click');
e.preventDefault();
} else {
alert($(this).attr('checked') ? 'checked': 'unchecked');
}
});
But the name never equals label? What am I doing wrong?
Quick jsfiddle
You should select the
label(parent) element. Currently the only target of your click handler is the input element:http://jsfiddle.net/j7nSq/