MooTools - Detect the Array Index of the Class Clicked
Can anyone tell me how I can detect the array index of the class clicked.
So if I had:
HTML
<span class="test">first</span>
<span class="test开发者_开发知识库">second</span>
<span class="test">third</span>
MooTools JS
$$('.test').addEvent('click', function(event){
// alert(this array index);
});
Any help would be great, Thanks!
very simple - don't .addEvent
, which will do the .each for you, but write the .each
yourself instead, it supports element, index
:
$$('.test').each(function(el, index) {
el.addEvent('click', function(event){
alert(index); // 0, 1, 2
});
});
精彩评论