mardi 22 septembre 2015

if statement won't work jquery

I am new to jQuery and I have been trying to get an image to change if a button to click. My only problem is that for some reason, the if statement that is supposed to check if the image number is less than 0 will not work. Here is my code:

$(document).ready(function(){
 var imageNumber = 0;

 $("#rightArrow").click(function(){
  imageNumber = imageNumber + 1;
  console.log(imageNumber);
  $("#image1").attr("src", "images/biohazard" + imageNumber + ".png");
 });

 $("#leftArrow").click(function(){
  if (imageNumber > 0) {
    imageNumber = imageNumber - 1;
    console.log(imageNumber);
    $("#image1").attr("src", "images/biohazard" + imageNumber + ".png");
  }
 });

});

Is there something I am doing wrong?

Aucun commentaire:

Enregistrer un commentaire