Jquery Adding Image Attribute Fix

时间:2018-12-03 13:07:58

标签: jquery

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>

1 个答案:

答案 0 :(得分:1)

instead of using .text()

use .html(), you might guess the difference