<div class="pagination"> <span class="prev"></span> <span class="num" id="1">1</span> <span class="num_active" id="2">2</span> <span class="num" id="3">3</span> <span class="num" id="4">4</span> <span class="num" id="5">5</span> <span class="num" id="6">6</span> <span class="next"></span> </div>
$('.pagination span').click(function(){ $(".pagination span").removeClass("num_active").addClass("num"); $(".pagination span:first").removeClass("num").addClass('prev'); $(".pagination span:last").removeClass("num").addClass('next'); $(this).addClass("num_active"); });