brian wilson
brian wilson

Reputation: 495

jquery has class and hover

I tried the code:

$('a').hasClass('button-hello').hover(function() { alert('ffs'); });

I have tried this, without success. I am trying to trigger hover on any A link that has button-hello in the class.

Upvotes: 0

Views: 440

Answers (1)

Erik Philips
Erik Philips

Reputation: 54618

The following code:

$('a.button-hello').hover(function() { alert('ffs'); });

Will work on the following elements:

<a href="#" class="button-hello">A1</a>
<a href="#" class="button-hello a">A2</a>
<a href="#" class="button-hello a b">A3</a>
<a href="#" class="button-hello a b c">A4</a>

JsFiddle.net Example

Upvotes: 3

Related Questions