HTML:
Div 1 Div 2 Div 3 <
Easy fix - .each supports index :
$(".test").each(function(idx){ alert(idx); });