Detecting DOM event support in Firefox

Posted by Andy E on Stack Overflow See other posts from Stack Overflow or by Andy E
Published on 2010-04-01T17:22:30Z Indexed on 2010/04/01 17:33 UTC
Read the original article Hit count: 249

Filed under:
|
|

What's the best way to detect event support in Firefox. Opera, Internet Explorer and Safari/Chrome all support eventName in object, but Firefox doesn't. My test case is this:

javascript:alert("onclick" in document.createElement("a"))

Which alerts true when entered into the address bar on the aforementioned browsers, and alerts false for Firefox. I figured out a solution using typeof on an event like so:

var a = document.createElement("a");
a.setAttribute("onclick", "");
alert(typeof(a.onclick) == "function");

Is there a better method of detecting event support in Firefox?

© Stack Overflow or respective owner

Related posts about firefox

Related posts about JavaScript