Skip to content

Instantly share code, notes, and snippets.

@Scanerrr
Last active September 25, 2018 09:22
Show Gist options
  • Save Scanerrr/b02a6dd926d75b57f2f7bf6a7e4c1393 to your computer and use it in GitHub Desktop.
Save Scanerrr/b02a6dd926d75b57f2f7bf6a7e4c1393 to your computer and use it in GitHub Desktop.
Load image preview from file input
function readURL(input) {
const file = input.files
const img = document.querySelector('.image-preview img')
if (!file || !file[0]) return img.src = '';
img.src = URL.createObjectURL(file[0])
}
$('.avatar-input').on('change', e => readURL(e.target))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment