Just discovered a crazy thing using jQuery and I just can't explain it. In the return of a $.getJSON, I've to unset/set some checkbox regarding to which categories are returned by the JSON. Before calling the JSON, I did :
$("input[type='checkbox'][name^='category_']").each(function() { this.checked = false; });
Which works perfectly. Then, inside the result function of the getJSON, I did this:
var checkedCats = data.categories.split(';');
for (i=0; i<checkedCats.length; i++) {
$('#category_'+checkedCats[i]).attr('checked',true);
}
And that works... randomly... Sometimes checking boxes, sometimes not... The craziest thing is that, when I transform this code to:
var checkedCats = data.categories.split(';');
for (i=0; i<checkedCats.length; i++) {
var aCheckbox = document.getElementById('category_'+checkedCats[i]);
aCheckbox.checked = true;
}
Then this code works perfectly...
Is there any reason ?