I am using .index() to get the position of the element. So by default it returns 0 for first one. Is there is a way to set default to 1 so the returned index would be 1,2,3… instead of 0,1,2…?
<div class="tabs">
<a href="">1</a>
<a href="">2</a>
<a href="">3</a>
</div>
and the jQuery:
$(function(){
$('.tabs a').click(function(e){
var index = $('.tabs a').index(this);
console.log(index);
e.preventDefault();
});
});
You can’t change the default, but you could add it manually
If that’s not good enough, you could create a plugin that would return the value you want.
So you can then use
.myIndexand get jQuery’s index with 1 added to it.Live example