Skip to content

Instantly share code, notes, and snippets.

@arvi
Created May 13, 2016 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arvi/c795525894d5f8dbed407e4a666286d6 to your computer and use it in GitHub Desktop.
Save arvi/c795525894d5f8dbed407e4a666286d6 to your computer and use it in GitHub Desktop.
//JS
$(function () {
$(":file").change(function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
}
});
});
function imageIsLoaded(e) {
$('#image-container').attr('src', e.target.result);
};
//HTML
/*
<input type='file' />
<img id="image-container" src="#" alt="your image" />
*/
//source: http://jsfiddle.net/vacidesign/ja0tyj0f/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment