I´m doing a landing page and wanted to make the main image change when I click on other images. I´ve tried with this
<div class="thumb"> <ul> <li> <img id="img1" class="smallImg coupe" src="./assets/smallCar1.png" alt="small img"> </li> </ul> <ul> <li> <img id="img2" class="smallImg" src="./assets/smallCar2.png" alt="small img"> </li> </ul> <ul> <li> <img id="img3" class="smallImg" src="./assets/smallCar3.png" alt="small img"> </li> </ul> </div> function imageChange() { let picDefault = document.getElementById("img"); if ((picDefault = "img")) { picDefault.src = "./assets/img1.png"; } } picDefault.addEventListener(click, imageChange);
clickneeds to be in quotes inaddEventListener()picDefault()is local to the function, you can't use it outsideif ((picDefault = "img"))will never be true.picDefaultis a DOM element, not a string. What are you trying to do there?if ((picDefault = "img"))will always be true as it is an assignment with a "truesy" result :D ...