JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="uploader">
<button type="button" class="uploadimg">Open uploader</button>
<input type="file">
<img id="ImgUpload" alt="Your Image" />
<br>
<br>
</div>
<div class="cloned">
</div>
<button type="button" class="duplicate">Duplicate button</button>
CSS
input {
display: none;
}
JavaScript
$(function() {
$(document).on('change', "input:file", function() {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
}
});
});
function imageIsLoaded(e) {
$('#ImgUpload').attr('src', e.target.result);
};
$(document).on('click', '.uploadimg', function() {
$('input:file').click();
});
$('.duplicate').click(function() {
var toAppendElement = '<div class="uploader">' +
'<button type="button" class="uploadimg">Open uploader</button>' +
'<input type="file">' +
'<img id="ImgUpload" alt="Your Image" />' +
'<br><br></div>';
$(".cloned").append(toAppendElement);
})