I’m trying to do a pagination for Bing API 2.0 To show the pagination numbers I have set this code:
if (webResultTotal > 100)
{
$('.numbers:lt('+(100)+')').show();
}
This means that if the results are more than 100, then 100 pagination numbers (with Class numbers) have to show. Normally they have display:none;
So my problem is if the results are less than 100. I tried solving this by:
if (webResultTotal < 100)
{
$('.numbers:lt('+Math.min(webResultTotal)+')').hide();
}
This will hide the numbers which look like this:
<li class="numbers"><a href="#"> 1 </a></li>
<li class="numbers"><a href="#"> 2 </a></li>
<li class="numbers"><a href="#"> 3 </a></li> etc..
The problem is that it will hide BEGINNING FROM THE FIRST of the list instead of hiding the last numbers. So it will not show 1,2,3 Instead it will hide themm and show the last of the li items. How do I change the code in order to hide in a negative way, so hide the li items from the end —> begin instead of the other way around?
Please note that I stripped my code to make the question simple, my real code looks different.
Given that you have a “very large” number of
.numberselements in your page, and you want to show/hide the appropriate number based on the number of returned results, a good solution would be:However, the concept of having prepopulated the page with lots of elements might not be the best approach vs generating elements as required on the fly; unfortunately this is something that cannot be tackled without more information.