07/01/2009

JavaScript: Cancel Event Bubbling

Another common tidbit of JavaScript code:

Cancel event bubbling:

function stopEvent(evt){
evt = evt || window.event;
if (evt.stopPropagation){
evt.stopPropagation();
evt.preventDefault();
}else if(typeof evt.cancelBubble != "undefined"){
evt.cancelBubble = true;
evt.returnValue = false;
}
return false;
}

5 comments:

Anonymous said...

I would like too take time too Thank all the people for doing what you do and make this community great im a long time reader and first time poster so i just wanted to say thanks.

Matt Stark said...

Thanks! Please leave a comment if there is anything particular you would like help with.

Anonymous said...

You have to express more your opinion to attract more readers, because just a video or plain text without any personal approach is not that valuable. But it is just form my point of view

Matt Stark said...

IMHO you are reading this blog and it is plain text without a personal approach.

I have personally found while writing this blog that opinion gets me in trouble. I stick to the facts but do appreciate your perspective.

Anonymous said...

You have to express more your opinion to attract more readers, because just a video or plain text without any personal approach is not that valuable. But it is just form my point of view