Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery :gt() inclusive

I was wondering how to use jQuery's :gt() in an inclusive way. I am trying to show/hide table rows dynamically.

$('#' + tbodyId + ' > tr:gt(' + newRowStart + '):lt(' + rowsToShow + ')').show();

If i try to show the first 5 rows say, newRowStart = 0 and rowsToShow = 5. This will not show the first row. Setting it to -1 doesn't work either. It would be very helpful if there was an inclusive method like :gte(). Does anyone know how to do this?

Thanks

like image 998
Timothy Ruhle Avatar asked Jan 21 '23 07:01

Timothy Ruhle


2 Answers

One option is to use slice():

$('#'+tbodyId)
  .find('tr')
  .slice( newRowStart, newRowStart + rowsToShow ) // inclusive of starting point
  .show();
like image 159
Ken Redler Avatar answered Feb 02 '23 14:02

Ken Redler


I think you want the slice function:

How to select a range of elements in jQuery

like image 37
Steve Wellens Avatar answered Feb 02 '23 12:02

Steve Wellens