1

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!

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

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

This is what you mean, am I correct?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.