Created
October 8, 2019 20:32
-
-
Save claraj/e2d937bc81efa109f2e9891cffb5501f to your computer and use it in GitHub Desktop.
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
<img id="uploaded-image"> | |
<input id="image-input" type="file"> | |
<button id="upload">Click to upload</button> | |
<script> | |
let img = document.querySelector("#uploaded-image") | |
let input = document.querySelector("#image-input") | |
let button = document.querySelector('#upload') | |
let reader = new FileReader() | |
reader.addEventListener('load', function() { | |
img.src = reader.result | |
}, false) | |
button.addEventListener('click', function() { | |
console.log(input.files) | |
let filename = input.files[0] | |
// img.attributes.src = filename | |
reader.readAsDataURL(filename) | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment