$(function () {
$("#btn_del").hide();
$(".upload").on("change", function()
{
var files = !!this.files ? this.files : [];
var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg)$/;
if (!files.length || !window.FileReader) return; // no file selected, or no FileReader support
if (regex.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+")");
}
} else {
alert('Wrong file type!');
}
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.