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
nodeNamewill always be equal to the element you selected for the event. There's no way to attach to the label unless you select the label initially.e.target, basically the handler is executed as the event bubbled all the way down to the child element.