I have created a button that allows users to input an image, but I am struggling to display the picture on the screen. I tried creating an empty `img` element and changing its URL based on what I saw on another website, but it was not successful.
Here is the HTML code:
<input id="myImage" class="photo-upload" type="file" accept="image/*, image/jpeg"> <img id="the-picture" width="200" />
And here is the JavaScript code:
const uploadPictureButton = document.querySelector(".photo-upload"); uploadPictureButton.addEventListener("click", displayPicture); function displayPicture(event) { let image = document.getElementById("myImage"); image.src = URL.createObjectURL(event.target.files[0]); };