Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I make it so when I click a button my image changes?

I tried to create a function where when the button is clicked the source of the image changed, but it didn’t work.

    <img
      class="bowgart"
      id="bowgart"
      src="C:\Users\jbrir\Documents\BowgartWebsite2\images\bowgart.png"
      alt="Bowgart"
    />
    <script>
      function imgOpen() {
        document.getElementById("bowgart").src =
          "C:UsersjbrirDocumentsBowgartWebsite2imagesBowgart_open.jpeg";
      }
    </script>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The src needs to be a valid URL. You’re missing the file: URL scheme and all the / delimiters in the pathname.

function imgOpen() {
  document.getElementById("bowgart").src =
    "file:///C:/Users/jbrir/Documents/Bowgart/Website2/images/Bowgart_open.jpeg";
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading