views:

46

answers:

2

Hi,

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!

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

This is what you mean, am I correct?

Machiel
almost, but wrong syntax
yoda
+4  A: 

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..

Gaby
that's it, thanks!
yoda