Real object listener: solved

V

VK

Anyone who's interested.
I implemented my own way to always get the right registered event
listener in case of nested elements *without* using intrinsic handlers
(so say you want to keep your HTML/XML and scripting completely
separate).

In FF you do it by listening events on their phase 1 (up -> down).

In IE you do it by extending event attacher with the missing (by my
opinion) property: boolean isRegisteredListener.

It's not a product, I just was working on it during my other project.

May look at the test here:

<http://www.geocities.com/schools_ring/RealTarget.html>
 
V

VK

Or you avoid the attachEvent method and then use the this operator, instead.

Well, in my situation it's a unpredefined scope of handlers called by a
single event, so addEventListener/attachEvent was kind of a must.

But yes, the universal obj.onevent = ref would kill a good part of
these if's-else's (I hate them actually).
 
A

ASM

VK said:
Anyone who's interested.

May look at the test here:

<http://www.geocities.com/schools_ring/RealTarget.html>

doesn't work with my IE5.2 (Mac)

"no matter where inside that cell do you click."
no with Safari (in right cell : support clic only if is in green div)

Do not understand so much complication

in the case of your example
(tested in my IE5.2, Safari, FF10.4, iCab3.0)

function highlgt(){
var T = document.getElementsByTagName('TD');
for(var i=0;i<T.length;i++)
if(T.id)
T.onclick=
Function('this.className=this.className==\'cellHigh\'?\'cellLow\':\'cellHigh\';');
}
onload = highlgt;
 
M

Michael Winter

Well, in my situation it's a unpredefined scope of handlers called by a
single event, so addEventListener/attachEvent was kind of a must.

If you mean that you may have more than one listener on a single
element, then you still don't need the attachEvent method. It can be
emulated, which also adds support for other browsers with an event model
but no addEventListener method, and in doing so, you can get much better
behaviour.

[snip]

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top