View Full Version : Is this even possible create element and listening and fire event?

27 Aug 2010, 5:22 PM
I am looking at creating something like this in ExtJS, it seems that jQuery has a very nice handy feature here.


When I write the code like this, I get a weird error.

uncaught exception: Error listening for "ping". Element "undefined" doesn't exist.

The code is

freeNode = new Ext.Element('div');
freeNode.on('ping', function() {alert('You pinged me');});

Anyone have any ideas on how to achieve this?

27 Aug 2010, 11:42 PM
But do you really NEED an element?

If you just want to fire events from SOMETHING, instantiate an Observable.

var myComponent = new Ext.util.Observable();
myComponent.on('ping', function(){alert("ping");})

28 Aug 2010, 12:25 AM
Thanks Animal, I sort of figured I could do that. I was curious on more of whether one could create an element that was detached from the DOM and still be able to apply events to it.

Come to think of it I am not even sure of a good case that one would need too.

28 Aug 2010, 12:37 AM
There is no use case.

That blog post is just ignoring the heffalump in the room, that jQuery has no Observable base class!