Adding an image changer

Hey!
Here is me trying to alternate the display of one of two images but when I go my test site and click on the first image it doesn’t switch with the second image. Instead of that it’s the description of the first image that appears.
Is that because the dimension of the two images ? I don’t understand at all !

Hi @aray98 and welcome to the community :wave:

It’s hard to tell where the problem is without seeing the code. I don’t think it’s the dimensions.
Could you put your code on an online code editor that shows you problem? (At https://jsfiddle.net/ you can save a link to your code without creating an account)

Have a nice day,
Michael

1 Like

Hi ! Thank you for your response. Here is the code like you told me : https://jsfiddle.net/2d9wf43h/4/.

Have a nice day !

Thanks for putting the code online.

I don’t know if that happened when pasting the code into the editor, but you didn’t close the <img> tag with >.
When I click on the image, I see in the DevTools inspector that the src correctly toggles.

Maybe you just have a typo in the path or filename of the second image. This would explain that the alt text of the first image appears. Since you don’t change the alt attribute in JS, a missing image (because of the wrong path) would instead show the alt text of the first image that’s still present.

I hope that helps. :slightly_smiling_face:

Have a nice weekend,
Michael

1 Like

Yes, I already tried to close the tag with > but it didn’t change anything. And I checked the path of the second name multiple times too but the path is the same as the first image and the filename is just “kendrick” so I don’t understand… I even remove the description of the first image in the alt text and try without it.

But thank you for your help !

hi @aray98

just reconfirming what @mikoMK said are you sure the same name with extension in same letter case

also are the picture next to the other one and both inside folder images

if all that does not help then not sure if file permission has effect on that or not so give it a try and check both image permission

hope that help and have a nice day :slight_smile:

1 Like

You could also put both images side-by-side on your page with the exact paths from the src attribute on the JS code and see if they display correctly.

1 Like
  1. also could you try to open the image file and see if it valid file ?
  2. check the format of the file extension does not make file being of certain type

so based on your os try to find how to check for file type/format

and this the supported image format by most browser

  1. try a different image file and see if it work or not

hope that help and have a nice day :slight_smile:

1 Like

Hi !
I’m just an idiot… I just wrote the wrong file type for both of the images. :sweat_smile: Sorry for bothering you @mikoMK @justsomeone and thanks for your support.
Have a nice day,
Rayane

2 Likes

No problem! Everybody makes mistakes. :sweat_smile:

1 Like

i do worse do not be sorry and have a nice day you too :slight_smile:

1 Like