user2042916
user2042916

Reputation: 21

displaying an image in a div after selecting using jquery

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

Answers (1)

Sudhir Bastakoti
Sudhir Bastakoti

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

Related Questions