jquery cross browser solution
What is the jQuery equivalent to the following:
function stopEvent(evt)开发者_运维技巧 {
if (window.event) window.event.cancelBubble = true;
else evt.stopPropagation();
}
The jQuery Event object implements a stopPropagation
method which is a cross-browser way to prevent events from bubbling up the DOM tree. Example:
// when an anchor with id of someElement gets clicked
$("#someElement").click(function(e) {
e.stopPropagation();
});
Bear in mind, return false
has the same effect as calling both e.preventDefault()
and e.stopPropagation()
.
精彩评论