var img = $(".gallery img"); $(img).each(function() { $("#bild_spel div ul").append( $('<li/>').append(this) ); });
~Daniel Friesen (Dantman, Nadir-Seen-Fire) Gilles wrote: > For some reason your answer doesn't show on here. You might have mail > me directly, anyway if you want to insert the element straight away > instead of creating a new image element maybe the fact that you are > mixing string variable and an object in your appen() might cause the > problem. > > In your code if you alert this you will see that it isn't <img > src="......"> but an object, an image tag object, so i think your code > fail because you are tying to append a string and an object together. > > this is not a string. Try appending this on its own and see which > result it gives. > > This should work (also wont be wrapped in <li>) > > var img = $(".gallery img"); > $(img).each(function() { > $("#bild_spel div ul").append(this); > > }); > > You'll just need to wrap it in your <li> somewhere else > > On Mar 30, 12:17 pm, Gilles <gil...@netxtra.net> wrote: > >> Might want to try something like this instead: >> >> $(".gallery img").each(function() >> { >> $('#bild_spel div ul').append('<li><img src=" '+$(this).attr >> ('src')+' " alt=""></li>'); >> >> }); >> >> haven't tested it but I believe it's correct :) >> >> On Mar 30, 11:48 am, smurkas <marcus.dalg...@gmail.com> wrote: >> >> >>> Hello. >>> >>> I have a situation where I have grabbed a couple of images off a page >>> and want to insert them again into an unordered list. Grabbing the >>> images was no problem but I don't know what to write when inserting >>> them again. >>> The code below does not result in the images being inserted again, >>> instead each list item contains >>> [object HTMLImageElement] as text. I also tried wrapping this in $ >>> (this) but that didn't work either. The solution is probably dead >>> simple but right now I am missing it. Can anyone help me out? >>> >>> var img = $(".gallery img"); >>> $(img).each(function() { >>> $("#bild_spel div ul").append('<li>'+this+'</li>'); >>> >>> }); >>> >>> Kindly, Marcus. >>> > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---