How to show image preview before uploading it to the server?
Hello everyone! I'm a beginner frontend developer and I have a problem. I'm making a form for uploading a user avatar. I want the user to be able to select a file via `` and immediately see how the image will look without waiting for it to be sent to the server. But I can't get it to work.
Here is my current code:
```html
```
```javascript
const fileInput = document.getElementById('fileInput');
const preview = document.getElementById('preview');
fileInput.addEventListener('change', function() {
const file = this.files[0];
// Here I don't know what to do next
// I tried to just assign the path, but it doesn't work
preview.sr
No answers yet.
Log in to leave an answer