How do I find out, in what position a list item was clicked.
So, let's say I clicked the second list item:
<li><a href="#"><span>Tab 2</span></a></li>
Then, I would get an alert saying something like:
You clicked the second list item?
JQuery Code
$('#top-betting ul li:first').addClass('current');
$('#top-betting div:not(:first)').hide();
$('#top-betting ul li span').click(function()
{
...?
});
Markup
<div id="tabs">
<ul class="clearfix">
<li><a href="#"><span>Tab 1</span></a></li>
<li><a href="#"><span>Tab 2</span></a></li>
<li><a href="#"><span>Tab 3</span></a></li>
</ul>
<div>Content 1</div>
<div>Content 2</div>
<div>Content 3</div>
</div>
You're looking for the
index
method.index
is the method you're after.Check the jsFiddle: http://jsfiddle.net/9V9D2/
You can do it using
.closest()
and.index()
like this:Overall, I think this is what you're after: