Help on - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help on

AxxaaaAxxaaa Posts: 3Member
I'm trying to make it on my website so that if I click a button or image button , another div will load that image. What is the best way to do this?


  • Josh CodeJosh Code Posts: 675Member
    Try the following code snippet. This solution should work independent of popular libraries like jquery.

    Copy and paste this code into the HTML of a page and see if it does what you want.

    Change the image_url value to whatever image you have. You can give it an absolute or relative path.


    var image_url="myimage.png";

    function loadImageInDiv()
    // get reference to the div element that will contain the image
    var div = document.getElementById("imageDisplay");

    // remove children, if there are any.
    while (div.firstChild)

    var img = document.createElement("img");

    // add the image to the div so it becomes visible in the page.

Sign In or Register to comment.