cancel img upload

HTML

<div>
  <img id="image" style="display:none;" />
</div>
<input id="fileToUpload" type="file" name="pic" />
<button id="btnUpload">Upload Image</button>

JavaScript

(function () {
	$("#fileToUpload").on('change', function () {
    var reader = new FileReader();

    reader.onload = function (e) {
      // get loaded data and render thumbnail.
      $("#image").css('display', '');
      $("#image").attr('src', e.target.result);
    };

    reader.onabort = function (e) {
      // get loaded data and render thumbnail.
			confirm('hello')
    };
    
    // read the image file as a data URL.
    reader.readAsDataURL(this.files[0]);
		reader.abort();
  });
  
  $('#btnUpload').on('click', function () {
  	if (confirm('Are you sure you want to upload this Image?')) {
    	// your upload code here
    } else { // user clicked the cancel button
    	$("#fileToUpload").replaceWith($("#fileToUpload").clone());
      $("#image").css('display', 'none').attr('src', '');
    }
  });
})();