Display preview selected image in input type file using JQuery

Display preview selected image in input type file using JQuery

In this post we will give you information about Display preview selected image in input type file using JQuery. Hear we will give you detail about Display preview selected image in input type file using JQueryAnd how to use it also give you demo for it if it is necessary.

Sometimes we need to show preview of image before image upload. I mean when user will select new image from input=”file” then it will display preview of image. In this example you can see before upload it will display preview using jquery.

Example:

<html lang="en">

<head>

<title>Change image on select new image from file input</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>

</head>

<body>


<input type="file" name="file" id="profile-img">

<img src="" id="profile-img-tag" width="200px" />


<script type="text/javascript">

function readURL(input) {

if (input.files && input.files[0]) {

var reader = new FileReader();

reader.onload = function (e) {

$('#profile-img-tag').attr('src', e.target.result);

}

reader.readAsDataURL(input.files[0]);

}

}

$("#profile-img").change(function(){

readURL(this);

});

</script>


</body>

</html>

Hope this code and post will helped you for implement Display preview selected image in input type file using JQuery. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

77  +    =  78

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US