开发者

accessing element attributes with mootools selector

I'm trying to attach a mouseover event to all img elements of a gallery in a page (using Mooto开发者_开发问答ols). This is easy enough using something like

$$('img.mygalleryclass').addEvents({
mouseover: function(){
    alert(id);
    }
});

My question is, how do I alert the id of the element referenced in the $$ 'loop'? That "alert(id)" returns an error every time since id is not defined.

Thanks!


Pass the event argument to the mouseover function and then get the id of the target:

$$('img.mygalleryclass').addEvents({
    mouseover: function(e) {
        alert(e.target.id);
    }
});

Here's an example.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜