Reputation: 5897
I have a lot of elements with a .photo
class on my page.
I select them this way:
$('#photos-container .photo').hover ...
Is there a way to filter out the elements that didn't fire the hover event?
Upvotes: 2
Views: 64
Reputation: 32598
Similar to DaDaDom's answer, but it caches the elements so you don't reselect on every event.
var photos = $('#photos-container .photo').hover(function(e) {
var elementsThatDidntFire = photos.not(this);
});
Upvotes: 2
Reputation: 140220
$('#photos-container .photo').hover(function(e) {
var elementsThatDidntFire = $('#photos-container .photo').filter(function() {
return this !== e.target;
});
}, function() {
});
Upvotes: 1
Reputation: 30115
Use .not
filtering:
$('#photos-container .photo').hover(function() {
$('#photos-container .photo').not(this).addClass('hover');
}, function() {
$('#photos-container .photo').not(this).removeClass('hover');
});
Code: http://jsfiddle.net/T6xGj/5/
Upvotes: 2
Reputation: 6466
What about
$('#photos-container .photo').hover(function(e) {
var elementsThatDidntFire = $('#photos-container .photo').not(this);
}
Upvotes: 6