0

I've written some jQuery for a photo navigator, but it does not work when I press the "back" button. However, the back button DOES work when I click the "next" button first. To make matters worse, when I click the "back" button first, the "next" button stops working. Any ideas?

Here is the Code for the 2 buttons:

/* === Previous Button === */

$("#photo_show a#back").click(function(event) {

    var placeHolder2 = curPhoto;
    event.preventDefault();
    nextPhoto = curPhoto;
    curPhoto = placeHolder2.prev(); 
    if(curPhoto.length == 0){
            curPhoto = $("#gallery a:last");
    }
    $("span#display_photo").html("<img id=\"display_photo\" src=\"" + curPhoto.attr("href") + "\" width=\"500\" height=\"350\"/>");
    $("p#caption").html("<p id=\"caption\"><em>" + curPhoto.attr("title") + "</em></p>")    
});

/* === Next Button === */

$("#photo_show a#next").click(function(event) {

    var placeHolder = nextPhoto;
    event.preventDefault();
    curPhoto = nextPhoto;
    nextPhoto = placeHolder.next();
    if(nextPhoto.length == 0){
        nextPhoto = $("#gallery a:first");
    }

    $("span#display_photo").html("<img id=\"display_photo\" src=\"" + curPhoto.attr("href") + "\" width=\"500\" height=\"350\"/>");
    $("p#caption").html("<p id=\"caption\"><em>" + curPhoto.attr("title") + "</em></p>")
});
Blazemonger
  • 90,923
  • 26
  • 142
  • 180

0 Answers0