jquery Event.stopPropagation() seems not to work
Am I totally missing what this is supposed to do? I expect that if I call stopPropagation() on an event, handlers for that event won't get triggered on ancestor elements, but the example below isn't working that way (in FireFox 3 at least)..
<script type="text/javascript">
$("input").live("click", function(event){
console.log("input click handler called")
event.stopPropagation()
});
$("body").live("click", function(event){
console.log("body was click handler called. event.isPropagationStopped() returns: " + event.isPropagationStopped());
})
</script>
...
<body>
<input type="text" >
</body>
Live events don't follow the same event bubbling rules. See the documentation on live event handling.
Quote from reference above:
Live events do not bubble in the traditional manner and cannot be stopped using stopPropagation or stopImmediatePropagation. For example, take the case of two click events - one bound to "li" and another "li a". Should a click occur on the inner anchor BOTH events will be triggered. This is because when a $("li").bind("click", fn); is bound you're actually saying "Whenever a click event occurs on an LI element - or inside an LI element - trigger this click event." To stop further processing for a live event, fn must return false.