I am trying to run the following code:
I pass a parameter to a function, but it always matters the last object that goes through the loop. I read some articles about this in stackoverflow, but I could not figure out how to make it work in my solution.
An object is a JSON object returned from the server. All values ββare correct.
for(var i = 0;i<parents.length;i++){ var row = $(document.createElement("tr")); var colName = $(document.createElement("td")); var aDisplayCol = $(document.createElement("a")); var parentId = parents[i]['PARENT_ID']; aDisplayCol.attr("href","#").html(parents[i]['NAME']); aDisplayCol.bind('click',function(){ alert(parentId);}); colName.append(aDisplayCol); row.append(colName); $('#pages tbody').append(row);
}
thanks
source share