0

I append images to my div with this code:

$(function() { var imagesPreview = function(input, placetoinsert) { if (input.files) { var filesAmount = input.files.length; for (i = 0; i < filesAmount; i++) { var reader = new FileReader(); if (i>=5) { break; } reader.onload = function(event) { $($.parseHTML('<img>')).attr('src', event.target.result).appendTo('.preview').addClass('added_images'); } reader.readAsDataURL(input.files[i]); } } }; $('#gallery-photo-add').on('change', function() { imagesPreview(this, 'div.gallery'); }); }); 

Images I get from input file field in my view. And now I want append for each image another image like "delete". How can I do that?My div now is empty:

<div class="preview"> </div> 

1 Answer 1

0

I would simply create the html needed and just use something like this:

$($.parseHTML('<div class="someClass">close</div>')).appendTo('.preview'); 

And then just listen for

$('.someClass').click(function(){ // do stuff }); 
Sign up to request clarification or add additional context in comments.

4 Comments

but this code create element near image I appended before. I need to append some image "on" my previous appended image.
So you need to like print a cross on the image after its been printed to the screen?
I need to have like delete icon of each image. I can do this only for uploaded images. Maybe, I need just append img with some style? I was try to use position:relative and absolute of that images but it doesn't work.All image make one image in div.
Put in a code example, maybe use codepin, or pastebin or similar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.