0

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 Answer 1

1

instead of using .text()

use .html(), you might guess the difference

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.