yoda
yoda

Reputation: 10981

jQuery index selector

I'm trying to find out a way to know the index of a anchor tag inside a certain div (one div has multiple similar anchor tags), like this :

<div>
  <a>first</a>
  <a>second</a>
  <a>third</a>
</div>

I'm using jQuery, but so far found no sollution to find the index of the anchor I have the mouse currently over.

Any ideas?

Cheers!

Upvotes: 1

Views: 1172

Answers (2)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196236

This should work

$('div a').mouseover(
function(){
  alert( $('div a').index(this) );
}
);

some changes would be required if there are multiple divs with links inside them and you want to find the index in that specific group..

Upvotes: 4

Machiel
Machiel

Reputation: 1515

$("div a").hover(function() {
    var index = $(this).index();
});

This is what you mean, am I correct?

Upvotes: 2

Related Questions