Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
how to close or remove a specific image in a multi uploaded images functionality

Here I have multi uploading image functionality.

So here if the user selects Multiple images so using the below JavaScript code we can upload multiple images.

But here I want to enhance the functionality and the uploaded images should have a cross icon like close the image if the user doesn't want to upload the specific image he will be able to delete or remove the desired image, not all the image which image is not the good user can able to remove that image.

So please help me how can we achieve this

var loadFile = function(event) {
  for (let i = 0; i < event.target.files.length; i++) {
    var image = document.createElement('img');
    image.src = URL.createObjectURL(event.target.files[i]);
    image.id = "output";
    image.width = "200";
    document.querySelector(".cont").appendChild(image);
  }
};
<input required name="images" type="file" multiple class="form-control-file" onchange="loadFile(event)">
<p class="cont"></p>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

<!DOCTYPE html>
<html>
    <body>
        <input required name="images" type="file" multiple class="form-control-file" onchange="loadFile(event)">
        <div id="cont"></div>
    <body>
    <script>
        var loadFile = function(event) {
            var imgCont = document.getElementById("cont");
            for (let i = 0; i < event.target.files.length; i++) {
                var divElm = document.createElement('div');
                divElm.id = "rowdiv" + i;
                var spanElm = document.createElement('span');
                var image = document.createElement('img');
                image.src = URL.createObjectURL(event.target.files[i]);
                image.id = "output" + i;
                image.width = "200";
                spanElm.appendChild(image);
                var deleteImg = document.createElement('p');
                deleteImg.innerHTML = "x";
                deleteImg.onclick = function() {this.parentNode.remove()};
                divElm.appendChild(spanElm);
                divElm.appendChild(deleteImg);
                imgCont.appendChild(divElm);
            }
        };

    </script>
</html>
                

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!