change image on change in jQuery

Posted by

We will learn how to modify an image using jQuery’s change() event, which is tied to the imageList select element, in this article. The change() event handler is called when a different image is chosen by the user from the list. The value of the selected image is obtained by the change() event handler from the this keyword and set in the src attribute of the image element.

Step 1: use cdn

<script src=""></script>

Step 2: put form code in view file

<form action="">                   
<div class="row mb-3">
	<label for="example-text-input" class="col-sm-2 col-form-label">Profile
	<div class="col-sm-10">
		<input name="profile_image" id="image" type="file" class="form-control"
<div class="row mb-3">
	<label for="example-text-input" class="col-sm-2 col-form-label">Pic</label>
	<div class="col-sm-10">
		<img id="showImage" class="rounded avatar-lg"
			src="{{ asset('assets/images/small/img-5.jpg') }}" alt="card image cap">
	<div class="col-lg-2">
		<input type="submit" class="btn btn-primary" value="Update Profile">

Step 3: use below script

<script type="text/javascript">
        $(document).ready(function() {
            $('#image').change(function() {
                var reader = new FileReader();
                reader.onload = function(event) {


One response

Leave a Reply

Your email address will not be published. Required fields are marked *

Would love your thoughts, please comment.x