in php if i use Example
if (!empty(the input file)){
//is isset
}
how can i do this in JQuery
html :
<div id="trash1">
Clear image
<i class="fas fa-trash"></i>
</div>
<div id="image-preview">
<input type="file" name="image-upload" id="image-upload">
</div>
JQuery
$(document).ready(function() {
$("#trash1").click(function() {
$("#image-upload").val("");
$( "#trash1" ).hide();
$("#image-preview").click(function() {
var file = $("#image-upload").val();
if(file) {
$( "#trash1" ).show();
}else {
$( "#trash1" ).hide();
}
});
});
});
I have prepared an example of action here https://codepen.io/danny2018/pen/RYajPB When I am loading the file
The div named trash1 need to show if input file is load But it only works the second time Someone might know why this is happening