[html5] Propagating custom Events?

Ian Hickson ian at hixie.ch
Fri Apr 9 14:46:07 PDT 2010

On Fri, 9 Apr 2010, Rik Sagar wrote:
> Was the idea of allowing custom event types ever discussed for HTML5?
> Correct me if I'm wrong, but currently the document will only propagate
> events of known types (UIEvents MouseEvents MutationEvents HTMLEvents), and
> you can't add other event types to propagate via dispatchEvent()?
> I was trying to use the addEventListener()/dispatchEvent() model to
> distribute events in my (javascript) app.  I thought I would be able to do:
>    mydiv.addEventListener('my_event_1', cb, false);
> and later:
>    mydiv.dispatchEvent(evt);
> However, to do this I needed to create an event object (evt) and when I
> tried to create an event using document.createEvent() it seemed I could only
> use pre-existing event types.

You need to use an Event interface that the browser supports, but you can 
make custom events easily, just use the Event interface directly when 
calling createEvent().

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

More information about the Help mailing list