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;
}

6 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...

Hey guys. I've been a long time reader, but first time poster. I hope this isn't offtopic, if it is, please move it to the right category.

Anyways, I read about that new iPad that Apple came out with, and was taking a look at a few websites that actually show you how to get one free! This is just by completing a few surveys. If your interested, take a look here [url=http://free-apple-ipads.com]Free Apple iPad[/url]:

http://free-apple-ipads.com

A friend of mine told me that hers is on the way. It's worth a try, the offer expires soon.

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