Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

67
Views
my if condition wont hide accordingly my next and previous buttons

I need a if condition which hides the first page=1 previous button, and on page 8 it hides the next button i did use the below code and try but it is not hiding accordingly:

var page = 8;
if(page == 0){
    $("#prev-button").hide();
    $("#next-button").show();
}else if (page == 8) {
    $("#prev-button").show();
    $("#next-button").hide();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="load-more"  id="next-button">
  <a href="${nextUrl}" class="btn-on-white white">Next</a>
</div>  

<div class="previous" id="prev-button">
  <a href="${prevUrl}" class="btn-on-white-test white">Prev</a>
</div>

8 months ago · Juan Pablo Isaza
1 answers
Answer question

0

Maybe this will help you on what you're trying to achieve:

      var page = 0;
      $("#prev-button").hide();
      $("#next-button").show();

      function showBoth() {
        if (page < 8 && page > 0) {
          $("#prev-button").show();
          $("#next-button").show();
        }
      }

      $("#prev-button").on("click", function () {
        page--;
        showBoth();
        if (page == 0) $(this).hide();
      });
      $("#next-button").on("click", function () {
        page++;
        showBoth();
        if (page == 8) $(this).hide();
      });
8 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs