1

I am trying to preview images when button is clicked. Problem occuring is that when i click the first image it displays and then when i click the second image,both the images together are displayed.How can i display just one image at a time? Here is my jquery code,

function Preview(id)
{
 $("#Preview_modal").modal("show");
    $.post("readUserDetails.php", {
        id: id              
    },
     function (data, status) {  
     var user1 = JSON.parse(data);      
     $("#element").append($("<img />").attr('src', 'data:image/png;charset=utf8;base64,' + user1.image));
    });
}
0

2 Answers 2

3

Don't use append, append will add another element to the container. Use html instead, this will replace the existing content by the new one.

$("#element").html(
    $("<img />").attr('src', 'data:image/png;charset=utf8;base64,' + user1.image)
);
Sign up to request clarification or add additional context in comments.

1 Comment

Glad I could help. If this solved your problem, please select this as the answer to your question. :)
0

You are always appending to the element:

Try to empty it first:

$("#element").empty().append($("<img />").attr('src', 'data:image/png;charset=utf8;base64,' + user1.image));

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.