Garmaine Staff asked 2 years ago

I need to rotate image on the same onclick attribute. So, after first click image1 should change to image2, and on second click image2 should change back to image1. I wrote code bellow but it only change once, from image 1 to image2, but second click doesn't work anything.

function changeImage() {
  if (document.getElementById("image").src = "./images/image1.jpg") {
    document.getElementById("image").src = "./images/image3.jpg";
  }

  else {
    document.getElementById("image").src = "./images/image1.jpg";
  }
}