Q:

How to import images/change them on button click?  JavaScript

I am trying to import images from a folder on my server strictly using JavaScript so that I can switch it out with a new image on button click.  I know how to import photos using HTML, but is there a way to do it through JavaScript?  What is the best way to do this?  Any help, guidance or examples would be greatly appreciated. 

A:

You can embed an image within a dom element on your page.   Here is a really simple example html file which does this assuming the myimage.jpg file is in the same directory.   Check out w3schools for more info on javascript. 
<html>
    <head>
    <script type="text/javascript">
    function btnClick()
    {
        spanElement = document.getElementById("imgContainer");
        spanElement.innerHTML = '<img src="myimage.jpg" />';
    }
    </script>
    </head>
    <body>
        <button onclick="btnClick()">Show Image</button>
        <span id="imgContainer"></span>
    </body>
</html>

