View Full Version : Event Handling

06-07-2006, 02:15 AM

I have the following function:

headingClicked: function() {
//Delay the execution of this function by 1 second.
setTimeout(function() { var that = standardistaTableSorting.that;
var linkEl = getEventTarget(window.event);
.....// futher processing
}, 1000);
window.event holds the details of my current event. When I first call an alert on it it tells me that there is an object there. However, after I enter the function in the setTimeout() the window.event is null.
Does anybody know why window.event would lose its value in the setTimeout() function? Is there anyway I can keep its value so I can use it?

Hope someone can help,



06-07-2006, 03:32 PM
window.event would be set to any other event that occurs after that call?
possibly even a bubbled event to the next element, body, so forth.
if you must reuse the current one, you'd need to set it to a local variable and pass it, but even then, because you are pointing to a global object reference, it may not be the Event Object you are seeking ;)

var e = window.event;
setTimeout(function() {alert(e.srcElement.outerHTML)}, 1000);

and see if you get the expected element..

06-08-2006, 04:10 PM
window.event is also IE only. In compliant browsers, the event is passed as the first argument to the handler.