jeudi 4 avril 2019

How to make an IF statement work with multiple images?

this function up(click) is basically an up arrow and the onclick suppose to read the image inside the div "gallerym" so if image 1 is in the div and function up is on it should switch image 2,

and it does .

the problem is that i want image 3 to switch to image 4 (if image 3 is in the div) ) but it will switch to image 2 (instead of 4 ) what am i doing wrong ?? thank you so much!!

function up(click) {  
  var gallerym = document.getElementById('gallerym');
  var myImage = gallerym.querySelector('img');
  if (myImage.src = '../images/gallery/image1.jpg')
    {
      myImage.src = '../images/gallery/image2.jpg'
    }

else if (myImage.src = '../images/gallery/image3.jpg')
  {
    myImage.src = '../images/gallery/image4.jpg'
  }  
}

Aucun commentaire:

Enregistrer un commentaire