I have a paging system implemented for user comments and depending on which page you have clicked on I want to only show 3 page numbers in each direction. So if you clicked on page 6 then only show pages 2 - 9, so 7 total.
I have my html like so:
<div id="paging">
<span id="1" class="page"></span>
<span id="2" class="page"></span>
<span id="3" class="page"></span>
<span id="4" class="page"></span>
and so on...
</div>
jQuery/javascript like so:
$(".page").click(function() {
var clicked = $(this).attr("id");
var parent = $("#paging span");
$(parent).each(function() {
if($(this).attr("id")+ 3 >= clicked)
$(this).removeClass("hidden");
else
$(this).addClass("hidden");
});
});
So far all it does is apply the hidden class to any page numbers before the currently clicked one.
data-page.