You can do this very easily in jQuery (I see that you are using it) using this code:
$(function(){
$.each($('body *'), function(i, v) {
var index = (i + 1);
console.log(index);
});
})
JsFiddle example here: http://jsfiddle.net/u7kWF/
Pure JS Example:
var id = document.body.getElementsByTagName('*');
for(i=0; i<id.length;i++){
console.log(id[i]);
console.log(i + 1);
}
jsFiddle: http://jsfiddle.net/u7kWF/1/
source
share