Howdy, Stranger!

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

Categories

Help on button.click

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?

Comments

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

    [code]

    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)
    div.removeChild(div.firstChild);

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

    // add the image to the div so it becomes visible in the page.
    div.appendChild(img);
    }








    [/code]
Sign In or Register to comment.