I have this (simplification):
$(li).click(function{alert("test");});
<li>
<input>
</li>
What's the best way to bind an event to li but not fire when the user clicks on the input element?
I have this (simplification):
$(li).click(function{alert("test");});
<li>
<input>
</li>
What's the best way to bind an event to li but not fire when the user clicks on the input element?
One solution could involve using event.target.
In the event handler, use
if( $(event.target).is('input') )
return;
I think you'll have to manually filter it.
$(li).click(function(e) {
if ($(e.target).is("input")) {
alert("Test");
}
});
Try using the stopPropagation method on the Event object.
$('input').click(function(event) {
event.stopPropagation();
});
You could also target specific children (or direct children) of li using a combination of selectors:
$('li > input, li strong, li span').click( ... );