Donnerstag, November 14, 2013

AjaxEngine: get rid of event.srcElement

It’s time to say goodbye to some of the compatibility tricks in the AjaxEngine. Here is the first article on maintaining your Javascript code if you come from some older versions.

A note for the future

If time is beyond April 2014 (the time when Windows XP and IE 8 and older dies), you don’t need to read and understand. If you find a code that reads obj.srcElement, just change it to
You stumbled upon some old-browser-compatibility issue.


The srcElement property on event objects was introduced by Microsoft to find out what html element was actually meant when a event was fired. The AjaxEngine then implemented some tricky code to make this property available in other browser too:

  // enable using evt.srcElement in Mozilla/Firefox
  Event.prototype.__defineGetter__("srcElement", function () {
    var node =;
    while (node.nodeType != 1) node = node.parentNode;
    // test this:
    if (node != alert("Unexpected!")
    return node;

Now, the W3C standard defines a target property that has the same meaning and also Microsoft moves to use the standard conform property in the newer browsers. I strongly advise to not support these older browsers any more because they never will be fixed for security issues any more.

For now you should find the target object inside an event handler by using:

var obj = || evt.srcElement;

and starting with April 2014 you just should use:

var obj =;

Changes to AjaxEngine

I searched all “.srcElement” occurrences and changed them to the compatible assignment

var obj = || evt.srcElement;
An updated download archive is available as well as commits to the sourcecode repository:
or directly using subversion:
See also