var images = [1,2,3];
var rowCount = 0;
var TargetElement="body"; //html tag, .classTag, #htmlElementId
for(var image in images) {
// stripping stuff:
$(TargetElement).append('<li class="search-dogs"><a href="https://stackoverflow.com/questions/38268881/images/gallery/search-dogs/"+image+'.jpg" rel="lightbox"><img src="https://stackoverflow.com/questions/38268881/images/gallery/search-dogs/"+image+'.jpg"></a></li>');
}
solved Dynamic gallery