Is there a syntax for the following thing:
$$('.a-lot-of-elems').addEvent('someevent',somefunction);
Is there a syntax for the following thing:
$$('.a-lot-of-elems').addEvent('someevent',somefunction);
something like
var elements = $$('.a-lot-of-elems')
for(var i = 0 ; i < elements.length ; i = i + 1)
{
elements[i].addEvent(somefunction);
}
should do ya!
First off - the following will work just fine.
$$(selector).addEvents({
click: fn
});
Don't use for, to iterate through an element collection, use each instead:
$$(selector).each(function(el){
el.addEvents({
click: fn
});
});
Here's a working example: http://jsfiddle.net/EPYBx/
You are just missing the event type.
var someFunction = function(e) {
alert('clicked!');
}
$$('.a-lot-of-elems').addEvent('click', somefunction);
Alternatively, you can use
$$('.a-lot-of-elems').addEvent('click', function(e) {
alert('clicked!');
});