Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
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 button.click

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?

Comments

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

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