I need to check event name already attached/ observed on an element.
//foo is a button
var isEventObserved = ?// need help in this line
var evnName = ?;// how
If(isEventObserved && evnName === 'my:evn2')
{
$('foo').observe('my:evn1', mymethod1};
}
else
{
$('foo').observe('my:env2', mymethod2);
}
Here's what you are looking for
Event.cache[$('foo')._prototypeUID]
lists the events registered for the element.
Event.cache[$('foo')._prototypeUID]['element']
is a reference to the element being observed, the rest of the properties in the object are events registered on the element (custom or native)
so for your specific situation
if(Event.cache[$('foo')._prototypeUID]['my:evn2'] != undefined)
{
$('foo').observe('my:evn1', mymethod1);
}
else
{
$('foo').observe('my:env2', mymethod2);
}
Please note I tested this with the latest version of Prototype, 1.7.2