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.
精彩评论