Detecting an event dynamically assigned...
Guys,
Would be interested to see if someone can come up with a solution for
this one.
--[html/js]--
function foo() { alert("foo") }
function bar() { alert("bar") }
onload = function () {
document.getElementById("x").attachEvent("onclick",bar);
}
<div id="x" onclick="foo()"> ... </div>
--/--
The above will set two events onto the onclick of the <div>, my question
is how to detect the dynamically assigned event?
document.getElementById("x").onclick will return the foo() event, as
that is the attribute set inline. There is no .currentEvents colelction
like there is a .currentStyle one to show real time event assignments.
In fact doing..
var obj = document.getElementById("x");
for (var item in obj) { alert(item+":"+obj[item]) }
...doesn't show up anything that I could use to detect if the event has
been assigned.
I should say, I know that I can do a "blind" detach of the event set,
rather than detecting if it exists first, but that's a touch lame. And
yes I know that attach/detachEvent returns a boolean so I could pass
that on to a global variable and detect if the event has been set that
way, but again, a touch lame.
I'll use a workaround until I can think of something more suitable, but
if anyone can come up with an answer for this, I would be interested to
see it.
Many thanks in advance.
Regards,
Ric.
date: Fri, 18 Nov 2005 13:05:39 +0000
author: Ric Paton