how to convert input type file into an icon

Solutions on MaxInterview for how to convert input type file into an icon by the best coders in the world

showing results for - "how to convert input type file into an icon"
Sam
08 Sep 2018
1<div class="image-upload">
2      <label for="file-input">
3        <img id="previewImg" src="https://icon-library.net/images/upload-photo-icon/upload-photo-icon-21.jpg" style="width: 100px; height: 100px;" />
4      </label>
5
6      <input id="file-input" type="file" onchange="previewFile(this);" style="display: none;" />
7    </div>
8
9
10
11
12<script>
13        function previewFile(input){
14            var file = $("input[type=file]").get(0).files[0];
15
16            if(file){
17              var reader = new FileReader();
18
19              reader.onload = function(){
20                  $("#previewImg").attr("src", reader.result);
21              }
22
23              reader.readAsDataURL(file);
24            }
25        }
26    </script>
27