Skip to content

Instantly share code, notes, and snippets.

@mudassaralichouhan
Created November 28, 2022 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mudassaralichouhan/57978b878293fa45a626341c4fa56b28 to your computer and use it in GitHub Desktop.
Save mudassaralichouhan/57978b878293fa45a626341c4fa56b28 to your computer and use it in GitHub Desktop.
display selected image
<script>
document.querySelectorAll('input[type="file"]').forEach((el, index) => {
el.onchange = e => {
const file = e.target.files[0];
if ( file ) {
el.closest('div[class*="col-md"]')
.querySelector('img').src = URL.createObjectURL(file);
}
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment