vibskov
vibskov

Reputation: 275

How to hook several div to hover?

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

Answers (3)

vibskov
vibskov

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

PSR
PSR

Reputation: 40318

You can separate using ,

$('.a, .b, .c').hover(function(){
  ......
});

or

 var all = $('.a, .b, .c');

 $(all).hover(function(){
  ......
});

Upvotes: 1

Raver0124
Raver0124

Reputation: 522

you can do

$('.a, .b, .c').hover()

Upvotes: 2

Related Questions