Please tell me what I’m doing wrong:
I’m trying to create id for each children in specific element. The following code doesn’t work:
$.get("/subject/list/", function(data){
$("#subject-description-main-menu-list").children().each(function() {
var pk;
var subject;
for (var i=0; i<data.length; i++) {
pk = data[i]['fields']['pk'];
subject = data[i]['fields']['name'];
};
$(this).attr("id","subject_"+subject+pk);
});
the rest of the code works fine!
And Google chrome console does not give me any errors,
but id of the elements do not change.
you runs through the children to create a id for it?
in the for-loop you run through a data object and you set the pk and subject. the pk and subject always set with the last elements of the data object, because you runs through the whole data object and override pk and subject.
therefore pk and subject are always the same values. if you will set different ids for each children you not override pk and subject.
hope this is helpfull.