Reputation: 1968
i am facing a problem when am trying to bind a array with the ids of my div's i wanted to bind them in order of their appearance staring with first to last.. The code:
i=1;
$('.hiddenvalue').each(function(){
arrayinit[i] = $(this).attr("id");
i++;
});
but its binding in any random order, why is it so? any suggestions?
Upvotes: 1
Views: 324
Reputation: 11211
"i" seems redundant. Try...
$('.hiddenvalue').each(function(){
arrayinit.push( $(this).attr("id") );
});
Upvotes: 3
Reputation: 2382
does this give you the same results ?
var arrayinit=[];
$('.hiddenvalue').each(function(){
arrayinit.push($(this).attr("id"));
});
I'm not sure it'll change the order, i think the order is more the same as it appear in the DOM tree does your .hiddenvalue divs appear in the correct order in the DOM tree ?
Upvotes: 2
Reputation: 50976
try this one instead
$('.hiddenvalue').each(function(i){
i++;
arrayinit[i] = $(this).attr("id");
});
However, I'm not quite sure why is it happening.
Upvotes: 1