JSFiddle - React, Tailwind, and code Playground

by werty1001

HTML

<span id="pagination"> 
    <a href="#">1</a> 
    <a href="#">2</a> 
    <a href="#">3</a> 
    <a href="#">4</a> 
    <a href="#">5</a> 
    <a href="#">6</a> 
    <a href="#">7</a> 
</span>

CSS

#pagination .active {background:red;color:#fff;}

JavaScript

$('#pagination a').each(function(i){
    
    var a=$(this),index=i;
    localStorage.getItem('pagination_active')==index&&a.addClass("active");
        
    a.on('click',function(){
        
        a.addClass('active').siblings().removeClass('active');            
        localStorage.removeItem('pagination_active');
        localStorage.setItem('pagination_active',index);
        
    });
    
});