jQuery: Which Element Triggered Function?
I've got some thumbnails that I animate a border onto when moused over.
I use hover()
to assign the functions when document.ready()
is called. What I'd like is a way to disable this animation effect on the image that the user has clicked on. It has a different class. So, I was planning on doing this by making the animate function include a check to see if the thumb in question had this other class. If not, proceed; if so, do nothing. But to do that I'd need to know which 开发者_如何学Gothumbnail (they have unique IDs) triggered the function. Ideas?
Thanks!
$('.thumbs').hover(function(){
if ($(this).hasClass('clicked')) return;
//animate here
});
You can get the target element of the event, like this:
$(".foo").hover(function(e) {
alert(e.target.id);
alert(e.target.tagName);
$(e.target).find(".blahblah").hide();
// etc.
}, function(e) {
...
});
You could make a live
handler that excludes the class by writing
$('selector:not(.someClass)').live({
mouseenter: function() {
},
mouseleave: function() {
}
});
精彩评论