javascript - Hide or remove next button after 3 clicks and show again if click on previous button -
i have done basic jquery code when clicking 3 time on next button hides , when click on previous button shows doesn't run 3 click loop. need make after clicking 3 time on next button when click on previous button should run first loop 3 click.
var $i = 1; $('body').on('click','#next',function(){ if ($i < 3) { /*functions executed*/ $i++; } else { $(this).prop('disabled', 1); $(this).hide(); } }); $('#prev').click(function() { $('#next').show(); }); var $n = 1; $('body').on('click','#prev',function(){ if ($n < 3) { /*functions executed*/ $n++; } else { $(this).prop('disabled', 1); $(this).hide(); } }); $('#next').click(function() { $('#prev').show(); });
you forgot reset counters:
var $i = 1; var $n = 1; $('body').on('click','#next',function(){ if ($i < 3) { /*functions executed*/ $i++; } else { $(this).prop('disabled', 1); $(this).hide(); $("#prev").show(); // <- show here $i = 1; } }); $('body').on('click','#prev',function(){ if ($n < 3) { /*functions executed*/ $n++; } else { $(this).prop('disabled', 1); $(this).hide(); $("#next").show(); // <- show here $n = 1; } });
Comments
Post a Comment