I'm not sure if you're trying to send back the image or just the src but, either way:
$(function() { $('li').each(function() { var self = this; $.post('getImg.php', {id: $(self).attr('id')}, function($data) { // ${self} refers to the li element }); }); }); On Tue, Dec 1, 2009 at 7:58 AM, David .Wu <chan1...@gmail.com> wrote: > <ul> > <li id="1"></li> > <li id="2"></li> > <li id="3"></li> > </ul> > > $(function() { > $('li').each(function() { > var $id = $(this).attr('id'); > $.post('getImg.php', {id: $id}, function($data) { > // How to do it? > }); > }); > }); > > I want to let each li use ajax load their own image and put into > thierself, the result shold like below, but if I user $.post, I don't > know how to put it to the right li. > <ul> > <li id="1"><img src="1.jpg"></li> > <li id="2"><img src="2.jpg"></li> > <li id="3"><img src="3.jpg"></li> > </ul> >