Martin Honnen wrote:
[...]
Tested to work with the examples in that page in Netscape 7, IE 6, Opera
7, should work with IE 5, Netscape 6, other Mozilla based browsers too,
hopefully Konqueror and Safari too but I haven't tested with those.
I tried your page - an issue with Safari when using:
target = evt.target;
is that evt.target will return the element actually clicked on,
including children of the element with the onclick. So if you have an
onclick handler on a td with some text in it and the user clicks on the
text, evt.target will be a reference to the text node, not the td.
In the case of your example above, the onclick is on the TR, but if I
click on the text in a cell, evt.target returns a reference to the text
node, not the cell, so when you call for the parentNode, you get the
cell not the row. Similarly for other elements such as LI & IMG.
I do not have any elegant way of dealing with this, I suppose you could
just climb up the parent tree to see the first parent element that has
an onclick that matches the event, but that may not be reliable. If
there is an onclick on a td and its parent tr, I don't know if you can
tell which one was clicked on.
Of course if the onclick passes "this" then you get an explicit
reference to the element whose onclick fired - and life is sweet.