0

I'm using the jQuery .slice() method to show and hide iterations of a class. The issue i'm having is hiding a button upon reaching the last child this class.

Here is the fiddle - https://jsfiddle.net/carbot3000/syq7s06g/5/

How could I hide the button class 'next' upon reaching last child of class 'review'? You'll see right now that the button is only hidden after clicking 'next' again upon reaching the last child.

if (start + x < size_li) {
  rvwList.slice(start, start + x).hide();
  start += x;
  rvwList.slice(start, start + x).show();
} else if (start + x >= size_li) {
  $('.next').hide();`
}
Will Ray
  • 10,621
  • 3
  • 46
  • 61
Carter Steinhoff
  • 41
  • 1
  • 1
  • 9

1 Answers1

0

Please use this code

var rvwList = $("#areaall .review").hide();
rvwList.slice(0, 2).show();
var size_li = rvwList.length;
var x = 2;
start = 0;

function showHide(){
if ( $("#areaall div").last().text().trim() == $(".review div:visible").last().text().trim())
  {
    $('.next').hide();
  }
  else if ($("#areaall div").first().text().trim() == $(".review:visible div").first().text().trim()) {
    $('.prev').hide();
  }
}

$('.next').click(function() {
  $('.prev').show();

    rvwList.slice(start, start + x).hide();
    start += x;
    rvwList.slice(start, start + x).show();
    showHide();
    console.log('size_li is:' + size_li);
    console.log('start is:' + start);
    console.log('start is:' + end);  
});
$('.prev').click(function() {
    $('.next').show();
    rvwList.slice(start, start + x).hide();
    start -= x;
    rvwList.slice(start, start + x).show();
    showHide();
});

I have updated your Fiddle. Please check.

Aneesh Sivaraman
  • 931
  • 1
  • 5
  • 9
  • This is a perfect solution for the context I gave. However, my actual content I'm working with is more complex than just text in a div. How would I go about implementing if what I was targeting is the code included below?
    " We were treated in a courteous, professional manner and every ."
    – Carter Steinhoff Sep 07 '16 at 18:10
  • Please create a new fiddle – Aneesh Sivaraman Sep 09 '16 at 05:54
  • I created a new question and the fiddle is in it. http://stackoverflow.com/questions/39401977/next-button-appearing-when-shouldnt – Carter Steinhoff Sep 09 '16 at 16:29