Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Korveld/c4af2a15401d469e9fbd15fe16727564 to your computer and use it in GitHub Desktop.

Select an option

Save Korveld/c4af2a15401d469e9fbd15fe16727564 to your computer and use it in GitHub Desktop.
Preview an image before it is uploaded on input file upload
var readURL = function(input) {
if (input.files && input.files[0]) {
var reader = new FileReader()
reader.onload = function(e) {
$('.photo__img-wrap img').attr('src', e.target.result)
}
reader.readAsDataURL(input.files[0])
}
}
$('#photoInput').on('change', function() {
readURL(this)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment