Bahram
Bahram

Reputation: 87

How to do multiple repetitive functions after click each of two buttons

I have 2 buttons and a "div". after the clicking on the each of "next" or "back" buttons , I want the "div" to slide left pr right; It is working for the first time I click "next" and first time for "back". after clicking on "back" button , the code seems not running. now why this happens? and how can I fix this?

 $(function () {
       $('.next_btn1').click(function () {
         $('#productExample').animate({
       left: 444
     });
   });

   $('.back_btn1').click(function () {
     $('#productExample').animate({
       right: 0
     });
   });

Upvotes: 0

Views: 22

Answers (1)

Waldir Bolanos
Waldir Bolanos

Reputation: 423

Heres a fiddle: https://jsfiddle.net/wwWaldi/h15jxrb4/10/

 $(function () {
    $('.next_btn1').on('click', function () {
        $('#productExample').animate({ left: 444 });
    });

    $('.back_btn1').on('click', function () {
        $('#productExample').animate({ left: 0 });
    });
});

In order to go back to the original position you just set left back to 0

Upvotes: 1

Related Questions