Currently I am working on file uploading using pure jquery with out any plugins. I need to upload only Jpeg and I need to view in the same container, i need to delete the image once the image is loaded. Initially my delete was hide because I have not uploaded any image.
Here is my current code
<div class="choose_file" id="imageUploadForm">
<span >Photo</span>
<input name="Select File" class="upload" type="file" />
</div>
<button id="btn_del" class="btn_del">Delete</button>
Here is my Jquery code
$(function () {
$("#btn_del").hide();
$(".upload").on("change", function()
{
var name = file.name;
var size = file.size;
var type = file.type;
var files = !!this.files ? this.files : [];
if (!files.length || !window.FileReader) return; // no file selected, or no FileReader support
if (/^image/.test( files[0].type)){ // only image file
var reader = new FileReader(); // instance of the FileReader
reader.readAsDataURL(files[0]); // read the local file
$("#btn_del").show();
$("#btn_del").on("click", function()
{
$("#imageUploadForm").css("background-image", "none");
$("#btn_del").css("display", "none");
});
reader.onload = function(){ // set image data as background of div
$("#imageUploadForm").css("background-image", "url("+this.result+")");
}
}
});
});
Actually I cannot able to see image in the contianer and I am not getting the delete button though. Acutally I have set the variable for the type But I have confused where i need to give the file type and how to check.
Kindly guide me
Here is the fiddle Link
Kindly help me