I have this code
var input = $("form input[name='name'].dhxlist_txt_textarea");
$(input).live('click', function () {
开发者_如何学Go ShowLookupGrid();
});
Then I've putted a second live binding before the first get executed
$('#Id').live('click', function () {
return false;
});
But the return false statement isn't stoping bubbling up the event to the second binding.
This should stop any other events of the same type being fired on that element as long as it is the first event handler that is run.
$('#Id').live('click', function (event) {
event.stopImmediatePropagation()
});
JSFiddle Example
This is not event bubbling, you are attaching a handler twice to the same element (one through the id selector and other one through element selector).
here written clearly
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.
work around for .live()
event propagation issues.
nodes created dynamically will not receive the event until after their parent has received it.
this will cause funkyness and stopPropagation and preventDefault will not solve this issue.
To Fix: add the lines
if(event.target != this){
return true;
}
to the top of the parent nodes event handler. this will stop the parent event from firing when the event is actually addressed to a child node, and (unlike return false) will propagate the event to the intended node.
精彩评论