JSFiddle - React, Tailwind, and code Playground
HTML
<input type="file" id="files" />
<img id="image" />
<div id="uploadimage"> upload image</div>
<a href="#" id="delete"> Delete</a>
<script>
document.getElementById("uploadimage").onclick=function(){
document.getElementById("files").click();
};
document.getElementById("files").onchange = function () {
var reader = new FileReader();
reader.onload = function (e) {
// get loaded data and render thumbnail.
document.getElementById("image").src = e.target.result;
};
// read the image file as a data URL.
reader.readAsDataURL(this.files[0]);
};
document.getElementById("delete").onclick = function () {
document.getElementById("image").src = '';
document.getElementById("files").value = null;
return false;
};
</script>