The Brain-Slurping Abomination Of The "onclick" Listener On An Anchor Added With "addEventListener" – Return Value Hell

If you add an onclick listener to an anchor with addEventListener, the return value is ignored and whatever is in the href is activated.

I come across this issue every day and have written about it before, but its only after coming out the other end of writing my addEventListener wrapper/replacement that I really appreciate just how mind bogglingly out of place this behavior is.

If this was a natural phenomena, creationists would simply have to throw their hands in the air and acknowledege that there was obviously nobody at the wheel.

Advertisements

About metawrap

CTO Massive Interactive. Ex Computer Whiz Kid - Now Grumpy Old Guru.
This entry was posted in JavaScript, Rants. Bookmark the permalink.

One Response to The Brain-Slurping Abomination Of The "onclick" Listener On An Anchor Added With "addEventListener" – Return Value Hell

  1. Did you try event.preventDefault() ? That seems to be the proper way in the W3C DOM Level 2 Events model to cancel the default action associated with an event. It works great for me on Gecko.

    Example :
    handleEvent(evt)
    {
    if (foo) bar();
    else evt.preventDefault();
    }

    Ref:
    http://developer.mozilla.org/en/docs/DOM:event.preventDefault
    http://news.hping.org/comp.lang.javascript.archive/5339.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s