Answers for "how to access the uploaded img in input tag from js"

8

how to display uploaded image in html using javascript

<p><input type="file"  accept="image/*" name="image" id="file"  onchange="loadFile(event)" style="display: none;"></p>
<p><label for="file" style="cursor: pointer;">Upload Image</label></p>
<p><img id="output" width="200" /></p>

<script>
var loadFile = function(event) {
	var image = document.getElementById('output');
	image.src = URL.createObjectURL(event.target.files[0]);
};
</script>
Posted by: Guest on April-22-2021
0

input file img / input file image

<div class="image-upload">
  <label for="file-input">
    <img src="https://icons.iconarchive.com/icons/dtafalonso/android-lollipop/128/Downloads-icon.png"/>
  </label>

  <input id="file-input" type="file" />
</div>


 // CSS

.image-upload>input {
  display: none;
}
Posted by: Guest on March-18-2022

Code answers related to "how to access the uploaded img in input tag from js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language