Roy Tang

Programmer, engineer, scientist, critic, gamer, dreamer, and kid-at-heart.

Blog Notes Photos Links Archives About

All entries tagged javascript-events.

You can subscribe to an RSS feed of this list.

Aug 2009

  • Say I add events to an object using either addEventListener or attachEvent (depending on the browser); is it possible to later invoke those events programmatically?

    The events handlers are added/removed using an object like this:

    var Event = {
        add: function(obj,type,fn) {
            if (obj.attachEvent) {
                obj.attachEvent('on'+type,fn);
            } else {
                obj.addEventListener(type,fn,false);
            }
        },
        remove: function(obj,type,fn) {
            if (obj.detachEvent) {
                obj.detachEvent('on'+type,fn);
            } else {
                obj.removeEventListener(type,fn,false);
            }
        }
    }
    

    Or do I need to store copies of each handler and just add an Event.invoke(…) function?

    Edit: Also, jQuery is not an option :D