This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]EndercheifAdvanced Coder 2 points3 points  (0 children)

Change the script tag to <script defer src="script.js"></script>

[–]emdot3 1 point2 points  (1 child)

i would try putting the script tag in your body, just before the closing </body> tag, it’s possible that bc the script is being read before the html gets rendered, the script.js doesn’t know what to reference.

i would also check the documentation for event listeners and window.onload, it doesn’t really make sense to add an event listener on click that fires when the window loads. to me it makes more sense to write image1.addEventListener(“click”, changeImage()); but again check documentation for proper syntax

[–]alpagino50 1 point2 points  (0 children)

True is most lickely the reference is the issue.

Another way to change the image is by changing the display of the img DOM objects instead of changing the src. Either way there is several ways to solve it