开发者

accessing element attributes with mootools selector

开发者 https://www.devze.com 2023-02-16 20:42 出处:网络
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

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

精彩评论

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