Allerious Posted April 8, 2019 Share Posted April 8, 2019 I've tried to replicate the bulb on/off code using cards. I've copy/pasted the w3 code and change the image names to my own and it doesn't work. Can someone spot what is wrong here? I've attached a screen shot of what appears on my screen. The code for the small images of the card back and ace of spades are there just to show i'm using the correct image name/location. The idea is when i click the large card back image it should turn to the ace of spades but doesn't. https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_state_if_else2 <!DOCTYPE html> <html> <head> </head> <body> <img src="images/card back.jpg" width="50" height="50"> <img src="images/Ace Spades.png" width="50" height="50"> <img id="myImage" onclick="changeImage()" src="images/card back.jpg" width="100" height="180"> <script> function changeImage() { var image = document.getElementById("myImage"); if (image.src.match("card back")) { image.src = "images/Ace Spades.png"; } else { image.src = "images/card back.jpg"; } } </script> </body> </html> Link to comment Share on other sites More sharing options...
dsonesuk Posted April 8, 2019 Share Posted April 8, 2019 Replace space (which you should NOT have) in file name with hyphen, then try it. 1 Link to comment Share on other sites More sharing options...
Allerious Posted April 8, 2019 Author Share Posted April 8, 2019 Excellent that has sorted it. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now