After dragging divs in my javascript application... I want to assign a numeric class to all divs, ordered by the position. I've researched a lot, and builded the next... but it just does not work. (Inner HTML does not change)
var ele = document.getElementsByTagName("div");
var i = 0;
var MyDrags = [];
while(ele[i]) {
if(ele[i].id.substr(0, 4)=="drag") {
MyDrags["distance"]=parseInt(document.getElementById(ele[i].id).style.top,10);
MyDrags["id"]=ele[i].id;
}
i++;
}
MyDrags.sort(function(a,b) {
return a.distance - b.distance;
});
i = 0;
while(MyDrags["distance"][i]) {
document.getElementById(MyDrags["id"][i]).innerHTML=MyDrags["distance"][i];
i++;
}
MyDrags = []instead ofMyDrags = new Array()- it's cleaner and more performant.new Array()is always the fastest. However, I will change my way of creating Arrays :)