There are two ways to access the "event" object, based on the browser (some browsers might support both, I can't remember). One way is the global "event" object, which IE6-8 supports and which you are using.
The other way to do it is assume that the event object has been passed to the event handler, like this:
Code JavaScript:
function WhichElementIsThis(event) {
// ...
}
Certain browsers (Firefox, Chrome, IE9) will automatically pass the event object to your function. So for cross-browser compatability, you could do something like this:
Code JavaScript:
function WhichElementIsThis(event) {
event = event || window.event;
// ...
}
Off Topic:
Another cross-browser issue you'll run into is that not all browsers support the 'srcElement' property; some use 'target' instead, so you'll want to do this, too:
Code JavaScript:
function WhichElementIsThis(event) {
event = event || window.event;
var elem = event.target || event.srcElement;
// ...
}
Bookmarks