Hello,

please consider the following code example. It applies the onclick handler to 
all image tags, and through window.event it ensures that it works in IE too:

--------------------------------------------------
var imgs = $('foo').getElementsByTagName('img');
for(var i=0; i<imgs.length; i++) {
  // Apply onclick handler
  imgs[i].onclick=function() {
    var id = this.id || window.event;
    $(id).style.border = '1px solid white';
  }
}
--------------------------------------------------

This works just fine. Now how can i achieve the same with Event.Observe? I 
have replaced the "Apply onclick" part with the code pieces listed below. 
Unfortunately they don't work in IE, it throws 'null or not an object' in 
both cases.

1)-----------------------------------------------
  // Apply onclick handler
  Event.observe(imgs[i], 'click', function(){
    this.style.border = '1px solid white';
  }, false);
-------------------------------------------------

2)-----------------------------------------------
  // Apply onclick handler
  Event.observe(imgs[i], 'click', function(){
    var id = this.id || window.event;
    $(id).style.border = '1px solid white';
  }, false);
-------------------------------------------------

I have the feeling i'm missing some important background information here. Can 
the event be passed to the anonymous function, or how does it work? Any help 
is appreciated.

-- 
Dirk Eschler                            zeitform Internet Dienste
mailto:[EMAIL PROTECTED]              Fraunhoferstraße 5
PGP S/MIME: http://key.zeitform.de/ap   64283 Darmstadt, Germany
Tel./Fax: +49 (0)                       http://www.zeitform.de
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to