Skip to content

Instantly share code, notes, and snippets.

@jasjs1
Created May 20, 2023 18:31
Show Gist options
  • Save jasjs1/d27926480ed43a7257f054cd5985dd94 to your computer and use it in GitHub Desktop.
Save jasjs1/d27926480ed43a7257f054cd5985dd94 to your computer and use it in GitHub Desktop.
Image preview using HTML and JavaScript
// 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]);
}
}
<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