Getting the index of an element ".eq(x)"
Hi everyone!
New to JQuery and Javascript Libraries in general, I experimented and learned a lot of things in the last couple of weeks. Now I'm struggling with what I presume is a simple problem:
I want to get the index of a link when the user clicks on it.
Javascript code:
-
var myArray = ["a","b","c"];
$("#buttons a").click(function(){
var result = myArray[$(this).eq()]
alert(result);
})
HTML code:
-
<div id="buttons">
<a href="#" id="btnA" class="btn">button1</a><a href="#" id="btnB" class="btn">button2</a><a href="#" id="btnC" class="btn">button3</a>
</div>
The above code is a simple example of what I'm looking for, not the actual code I'm working on. I know the first <a> index is 0 ( $("#buttons a").eq(0) ) but I don't know how to get it when clicked. I searched in the documentation and forums but was not able to find something useful. I don't want to assign a class or id to these links as they already have one, just get its index.
Thanks for your help!