Reputation: 275
How can I hook several divs to hover? I use add()
but its not working.
var h1 = $('.a');
var h2 = $('.b');
var h3 = $('.c');
var all = h1.add(h2).add(h3);
all.stop(true, true).hover(function(){// not work
var this_id = $(this).filter('.a').attr('id');
// do something
}, function(){
...
});
Upvotes: 0
Views: 72
Reputation: 275
I get it, because var this_id = $(this).filter('.a').attr('id');
should change to $(this).attr('id')
Thanks for all answer let me sure add() is working!!!
Upvotes: 0
Reputation: 40318
You can separate using ,
$('.a, .b, .c').hover(function(){
......
});
or
var all = $('.a, .b, .c');
$(all).hover(function(){
......
});
Upvotes: 1