Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your function, I see you are using both <code>elemenet</code> and <code>element</code> where they should be the same spelling. That would be at least part of the problem.</p> <p>I also see that your <code>addEvents</code> function is a self executing function which doesn't make sense in this regard. It seems like it should just be a normal function.</p> <p>Here's my cross browser event function. In addition to make one function for adding event handlers, it also normalizes the <code>this</code> pointer and the <code>events</code> object so they can be treated the same in any browser too.</p> <pre><code>// add event cross browser function addEvent(elem, event, fn) { // avoid memory overhead of new anonymous functions for every event handler that's installed // by using local functions function listenHandler(e) { var ret = fn.apply(this, arguments); if (ret === false) { e.stopPropagation(); e.preventDefault(); } return(ret); } function attachHandler() { // set the this pointer same as addEventListener when fn is called // and make sure the event is passed to the fn also so that works the same too var ret = fn.call(elem, window.event); if (ret === false) { window.event.returnValue = false; window.event.cancelBubble = true; } return(ret); } if (elem.addEventListener) { elem.addEventListener(event, listenHandler, false); return {elem: elem, handler: listenHandler, event: event}; } else { elem.attachEvent("on" + event, attachHandler); return {elem: elem, handler: attachHandler, event: event}; } } function removeEvent(token) { if (token.elem.removeEventListener) { token.elem.removeEventListener(token.event, token.handler); } else { token.elem.detachEvent("on" + token.event, token.handler); } } </code></pre> <p>If you want a simpler version without the propagation and default prevention options but with <code>this</code> and <code>event</code> normalization, that would be this:</p> <pre><code>// add event cross browser function addEvent(elem, event, fn) { if (elem.addEventListener) { elem.addEventListener(event, fn, false); } else { elem.attachEvent("on" + event, function() { // set the this pointer same as addEventListener when fn is called return(fn.call(elem, window.event)); }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload