class method ActiveSupport.Element.observe
ActiveSupport.Element.observe(element,event_name,callback[,context]) → Function
- element (Element): The DOM element to observe.
- event_name (String): The name of the event, in all lower case, without the "on" prefix — e.g., "click" (not "onclick").
- callback (Function): The function to call when the event occurs.
- context (Object): The context to bind the callback to. Any additional arguments after context will be curried onto the callback. This implementation of event observation is loosely based on Prototype's, but instead of adding element.stopObserving() and event.stop() methods to the respective Element and Event objects, an event stopping callback and an event handler unregistration callback are passed into your event handler.
ActiveSupport.Element.observe(element,'click',function(event,stop,unregister){
stop();
unregister();
},this);
//Prototype equivelent:
var my_handler = element.observe('click',function(event){
event.stop();
element.stopObserving('click',my_handler);
}.bind(this));
dom:ready support is also built in:
ActiveSupport.Element.observe(document,'ready',function(){});
If the above call was made after the document 'ready' event had already fired, the callback would be called immediately.


