开发者

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
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜