HTML:
Div 1
Div 2
Div 3
<
why the output is
4, 6, 8, 10
$(this).index() returns the index of the element relative to its siblings, not to the selected elements. The br and .divX elements are siblings as well!
It looks like you want:
var $tests = $(".test");
$tests.each(function(){
var i = $tests.index(this);
alert(i);
});
or simpler:
$(".test").each(function(i){
alert(i);
});