Last active
September 25, 2018 09:22
-
-
Save Scanerrr/b02a6dd926d75b57f2f7bf6a7e4c1393 to your computer and use it in GitHub Desktop.
Load image preview from file input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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