0

I am trying to change imagesource with another image.

<script type="text/javascript">

    document.getElementById("imgbulb").onclick= function() {        

         document.getElementById("imgbulb").Src ="C:\Html\images\ bbc.png";

    }

</script>
6
  • 1
    probably a dupe: stackoverflow.com/questions/7312553/… In your case, try to use a lower-case src. Commented Jan 2, 2016 at 5:25
  • I have already tried with lower case 'src' but it didn't work. Commented Jan 2, 2016 at 5:29
  • Your browser is sandbox-ed and does does not have access to your local file system like this "C:\Html\images\bbc.png". Try something like "file://relative-path-to-file". Commented Jan 2, 2016 at 5:31
  • this is my modified code <body> <h1>My first javascript </h1> <img id="imgbulb" src="images\pic_bulboff.gif" > <script type="text/javascript"> document.getElementById("imgbulb").onclick= function() { document.getElementById("imgbulb").src = "images\pic_bulbon.gif" ; } </script> </body> Commented Jan 2, 2016 at 5:34
  • 1
    For starters, try this console.log("C:\Html\images\ bbc.png"). - recall that in JS as with many languages, ` is used to escape characters. E.g \n, \t. You can use two of them or you can reverse them and use forward slashes. I.e \` or / - this is the strings covered, but there are other issues too. :) Commented Jan 2, 2016 at 5:42

1 Answer 1

0

use relative path

document.getElementById("imgbulb").onclick= function() {        

     document.getElementById("imgbulb").src ="images/bbc.png";

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.