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>
m.R
  • 1
  • 1
    probably a dupe: http://stackoverflow.com/questions/7312553/change-image-source-with-javascript In your case, try to use a lower-case `src`. – Mario Tacke Jan 02 '16 at 05:25
  • I have already tried with lower case 'src' but it didn't work. – m.R Jan 02 '16 at 05: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". – Mario Tacke Jan 02 '16 at 05:31
  • this is my modified code

    My first javascript

    – m.R Jan 02 '16 at 05:34
  • Try [this](https://jsfiddle.net/Varn/hcbnr0jf/) – Monica Olejniczak Jan 02 '16 at 05:35
  • 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. :) – enhzflep Jan 02 '16 at 05:42

1 Answers1

0

use relative path

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

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

}
Scarecrow
  • 4,057
  • 3
  • 30
  • 56