Use event.srcElement
:
img.attachEvent("onclick", function(ev){
alert(ev.srcElement.id);
});
I would give you a JSFiddle, but JSFiddle fails in IE8.
EDIT: Another solution would to use a closure/variable solution. Something like this:
(function(){
var _img=img;
_img.attachEvent("onclick",function(ev){
alert(_img.id);
});
})();
This creates a local copy of img
so you can use it inside the event listener.
Beyond that my advice is to just forget IE 8 altogether. (J/K)