[thelist] unobtrusive JS: adding events with parameters?

Tom Dell'Aringa pixelmech at yahoo.com
Thu Jan 12 08:35:31 CST 2006

Hello listers, 

I'm using Scott Andrew's faithful addEvent() method[1] to add an event to some images at load time. My init function has this clause: 

function kButtonInit() 
  var inputs = document.getElementsByTagName('img'); 
  for(var y=0; y { 
    if(inputs[y].className == "kbutbool") 
      addEvent(inputs[y], "click", kButtonBool); 
The event gets added just fine. The problem is, I need to send one argument to kButtonBool, namely a 'this' reference to the img object itself like so:
Does anyone have any techniques for adding functions to handlers without placing them directly in the code?

[1] http://www.scottandrew.com/weblog/articles/cbs-events

More information about the thelist mailing list