Created
May 20, 2023 18:31
-
-
Save jasjs1/d27926480ed43a7257f054cd5985dd94 to your computer and use it in GitHub Desktop.
Image preview using HTML and JavaScript
This file contains 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
// JS | |
let img = document.getElementById('img'); | |
let input = document.getElementById('input'); | |
input.onchange = (e) => { | |
if (input.files [0]) { | |
img.src = URL.createObjectURL(input.files[0]); | |
} | |
} |
This file contains 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
<div> | |
<img id="img" src="choose.png" height="500"> | |
</div> | |
<input id="input" type="file"> | |
<script src="loadImage.js"</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment