Reputation: 2851
I have a n array of imag src attributes from images that I was able to push to an array:
var imgSrcArray = Array();
$('.ito-image').each(function(){
imgSrcArray.push($(this).attr('src'));
});
I want to take these attributes now and create new images for a different purpose on my webpage how can I do this. And is this he best practice?
Upvotes: 0
Views: 378
Reputation: 62498
you can iterate same way using $.each()
and append to some container div:
$(imgSrcArray).each(function (index, item) {
$("#new").append('<img src="' + item + '"/>');
});
or you can directly do it:
$('.ito-image').each(function(){
$("#new").append('<img src="' + $(this).attr("src") + '"/>');
});
http://jsfiddle.net/ehsansajjad465/0oh6mma0/
Upvotes: 2
Reputation: 14390
is that what u want ?
for (var i=0; i < imgSrcArray.length; i++){
$('body').append("<img src='"+ imgSrcArray[i] +"' />");
}
Upvotes: 2