jquery - How to delete the dynamically created image in the following code? -
this dynamically create image:
function handlefileselect(evt) { var files = evt.target.files; // filelist object // loop through filelist , render image files thumbnails. (var = 0, f; f = files[i]; i++) { // process image files. if (!f.type.match('image.*')) { continue; } filenames.push(f.name); var reader = new filereader(); // closure capture file information. reader.onload = (function(thefile) { return function(e) { // render thumbnail. var span = document.createelement('span'); span.innerhtml = ['<img class="thumb" id="',escape(thefile.name),'" src="',e.target.result, '" title="', escape(thefile.name), '"/><input class="delete" type="button" value="delete" name="',escape(thefile.name),'"/>'].join(''); document.getelementbyid('list').insertbefore(span, null); }; })(f); // read in image file data url. reader.readasdataurl(f); }
and want delete image when press button:
$('#list').on("click",".delete",function(e){ $(e.target).remove(); });
as image before button clicking
$('#list').on("click",".delete",function(e){ $(this).prev('img').remove(); });
Comments
Post a Comment