Tell me, please, how can a photo be inserted to <img>
, when I open
<input type = "file">
and choose any file ?
How can I use JS / JQuery ?
Asked
Active
Viewed 123 times
0

charlietfl
- 170,828
- 13
- 121
- 150

Spiderman5
- 23
- 5
-
Possible duplicate of [Preview an image before it is uploaded](http://stackoverflow.com/questions/4459379/preview-an-image-before-it-is-uploaded) – Aboodz Feb 28 '16 at 13:55
-
1Possible duplicate of [Loading an image to a
from ](http://stackoverflow.com/questions/3814231/loading-an-image-to-a-img-from-input-file) – Vincent Orback Feb 28 '16 at 14:21
1 Answers
0
Use 'FileReader' object:
$("#yourinput").change(function () {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function (e) {
$("#yourimg").attr("src", e.target.result);
}
reader.readAsDataURL(file);
});

MBN
- 1,006
- 7
- 17