Help on

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?


  • 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.

Howdy, Stranger!

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


In this Discussion