How can I Add an image element through jquery, I am trying but it is not working. When I upload a file, My image disappeared automatically. Am doing something wrong. Any Help will be Appreciated.
$('input[type=file]').change(function () {
$fileCount = this.files.length;
$(this).prev().text( " <img src='https://i.imgur.com/WXGYX4O.png' width='53px'> " + $fileCount + ' Pic selected');
})
input[type="file"] {
display: none;
}
.custom-file-upload {
display: inline-block;
padding: 6px 12px;
cursor: pointer;
}
.form {
background: #f7f7f7;
text-align: center;
padding: 15px 0;
}
.img_Camera_icon {
width: 53px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<div class="form">
<label for="file-upload" class="custom-file-upload">
<img src="https://i.imgur.com/WXGYX4O.png" alt="" class="img_Camera_icon">
0 Pic selected
</label>
<input id="file-upload" type="file">
</div>
</div>
答案 0 :(得分:1)
instead of using .text()
use .html()
, you might guess the difference