I have Add Attachment link which if clicked will create a file input and delete link. For example I have add 3 file inputs and if user click delete link for file input 2, it will delete file input 2 not the last file input, so it will delete only correspondingly file input.
How to code jquery for this case? also how to arrange the file input so it will add vertically?
I'm using Jasny Bootstrap for <input type="file"/>
View:
<div class="form-group">
<label class="control-label col-md-2">Attachment</label>
<div class="col-md-10">
<div id="attachments">
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-2"></div>
<div class="col-md-10"><a href="#" id="addAttachment">Add More</a></div>
</div>
Script:
$(document).ready(function () {
$("#addAttachment").click(function () {
$("#attachments").append("<div class='fileinput fileinput-new' data-provides='fileinput'><span class='btn btn-default btn-file'><span class='fileinput-new'>Select file</span><span class='fileinput-exists'>Change</span><input type='file' name='myFile'></span><span class='fileinput-filename'></span><a href='#' class='close fileinput-exists' data-dismiss='fileinput' style='float: none'>×</a></div>")
});
});