0

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?

2
  • Have you considered just copying/moving the images to whatever new place you want them appended? Commented Aug 15, 2014 at 19:41
  • did you try anything? Commented Aug 15, 2014 at 19:44

2 Answers 2

2

is that what u want ?

for (var i=0; i < imgSrcArray.length; i++){

  $('body').append("<img src='"+ imgSrcArray[i] +"' />");

}
Sign up to request clarification or add additional context in comments.

Comments

2

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") + '"/>');
});

FIDDLE:

http://jsfiddle.net/ehsansajjad465/0oh6mma0/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.