I was just reading http://api.jquery.com/event.stopPropagation/
Since the .live() method handles
events once they have propagated to
the top of the document, it is not
possible to stop propagation of live
events
I was a bit confused with this statement, Can someone please explain me the same with some example?
Live method binds a handler to the document, and identifies which element triggered the event from the
event.targetproperty.So the actual handler is at the top (in terms of hierarchy).
The
stopPropagationstops the bubbling from going up the DOM hierarchy, but since the handler is at the top already (in the.livecase) there is no upper place to bubble to ..example attempt ..
you bind a click event handler to the link (with the
bindorclickmethod).When you click the link, the handler is triggered, but in addition the click event goes up the DOM until it reaches the document, and will also trigger click handlers bound to the div and document. (unless you use the
.stopPropagation)Alternatively if you use the
.livemethod to bind the event handler, it will be bound to the document. If you now click the link, the event (which will not fire right away, since no handler is bound to it) will naturally go up the DOM (triggering the click handlers it encounters). Once it reaches the document it will trigger our own handler. But there is no upper to go, so thestopPropagationis useless at this point.