I made JS for displaying an image after selecting it. Here is the code
html code
<input type="file" id="file_photo" onchange="preview_image(event)" name="item_image" ></input>
<img id='output_image'/>
JS code
function preview_image(event){
document.getElementById('output_image').style.display='block';
var reader = new FileReader();
reader.onload = function(){
var output = document.getElementById('output_image');
output.src = reader.result;
}
reader.readAsDataURL(event.target.files[0]);
};
It success to display. But the question is, could I put the output image inside css url background image?
If the html is like this.
<label for="file_photo" class="file">
<div class="camera_icon" style="background: url() center center no-repeat #d7d7d7;background-size: cover;">
<img src="/public/img/stock/icon07.png">
<img src="/public/img/stock/icon06.png" class="plus_icon">
</div>
<input type="file" id="file_photo" onchange="preview_image(event)" name="item_image" ></input>
</label>
could I put the output image in
style="background: url() center center no-repeat #d7d7d7;background-size: cover;"
because I need to follow the css file.