Reputation: 21
How to display an image in a div using jQuery? I have this piece of code but it is not working.
$(document).ready(function () {
$("#up").click(function () {
var imgUrl = $("img_input").val();
$("#imageDiv").prop("src", imgUrl).show();
});
});
where up
is the id
given to:
<input id="img_input" type="file">
<button id="up">
Upvotes: 2
Views: 505
Reputation: 100175
change:
$("img_input").val();
to
$("#img_input").val();
If imageDiv
is id of div
and image exists inside it, then do:
$("#imageDiv").find("img").prop("src", imgUrl).show();
Upvotes: 2