javascript - HTML Auto Appending File Uploads -


i'm trying figure out how allow multiple file uploads. javascript code checks on change in file upload , if there change file has been chosen code append new file upload.

the issue works first time. know what's going on?

js file:

<script> $(".file").change(function() {     $(".file").each(function( index ) {         if ($(this).val() != "") {             console.log("empty");             $("#fileupload").after("<input class=\"file\" type=\"file\" name=\"file[]\" id=\"file\">");         }     }); }); </script> 

html:

<div id="fileupload" style="display: none;">     <input class="file" type="file" name="file[]" id="file"> </div> 

solved:

here working version stumbles upon thread:

$(document).on("change", ".file", function() {     if ($(this).val() != "") {         $("#fileupload").append("<input class=\"file\" type=\"file\" name=\"file[]\" id=\"file\"><br>");     } }); 

change $(".file").change(function(){ $(document).on("change", ".file", function(){

it happens because code runs in existing elements. proposed change works


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -