Thank you Microsoft!
Microsoft’s lame attachEvent protocol (instead of the standard addEventListener) doesn’t pass along the element that caught the event. So if you use attachEvent to attach something to, say, onclick, and then the user clicks that object, then the function you attached can’t do something like “this.id” because “this” isn’t defined. INSTEAD it’s part of the window.event object (there’s only one). this function returns the right object. Call it like so:


/* getClickedObject - returns an object that caught whatever event is in process
 *     note that this could be onload, onmouseover, etc.
 * var eventObject = getClickedObject(this);
 * then you can do eventObject.whatever and go about your business.
 */
function getClickedObject (obj) {
  var clickedElement = null;
  if (typeof obj != undefined && obj.tagName) {
     //this IS defined, so the browser is following the standards
      return obj;
  } else {
      //this isn't defined, which means IE is in play
      try {
        //get the element from the window event instead
        return window.event.srcElement;
      } catch (e){
      }
  }
}