I am using lis to obtain a list of <li>
from my DOM, and in each LI and update the projectPhoto after the ajax call. But my "li" in the callback function always referring to the last item in lis
, is there any way to overcome this, or such as pass as value ?
p/s: I am pretty sure this has been discussed before just that I can't reach it with the right terminology. Apology in advance.
var lis = $('.porject_list li');
for (var i = 0; i < lis.length; i++) {
var li = lis.eq(i);
var projectId = li.attr('data-project-id');
$.get("/webapi/projects/projectphoto/" + projectId, function (res) {
$("img", li).attr('src', res);
});
}