I am new to jQuery and I am trying to make a simple HTML loading page and I want to add a new file to create after selecting some file. I tried this code
<form id="upload" action="upload.php" method="POST" enctype="multipart/form-data" onchange="addField();"> <label for="file">Soubor:</label> <input type="file" name="files[]" id="file" /><br /> <input type="submit" name="Odeslat" value="Odeslat soubor" /> </form></body> <script> $('#upload').delegate('input[type=file]', 'change', function(){ alert('Alert'); addField(); }); </script>
and this addField () function
function addField(){ $('<input type="file" name="files[]" id="file" /><br />').insertAfter('#file'); };
But if I run this code, the third input field will be inserted after the first, and not after the last field. Is it possible to add input fields after the last file entry without using unique identifiers for these inputs? http://jsfiddle.net/aHrTd/
Thanks for any help.
source share