Add Active Class With Refresh Page

 $("#Selcetor-name li").click(function () {
        var id = $(this).attr("id");

        $('#' + id).siblings().find(".active").removeClass("active");
        //                       ^ you forgot this
        $('#' + id).addClass("active");
        localStorage.setItem("selectedolditem", id);
    });

    var selectedolditem = localStorage.getItem('selectedolditem');

    if (selectedolditem != null) {
        $('#' + selectedolditem).siblings().find(".active").removeClass("active");
        //                                        ^ you forgot this
        $('#' + selectedolditem).addClass("active");
    }

/********************************HTML***********************************/

<ul id="Selcetor-name">
                <li id="test1" class=""><a href="#"><span>test</span></a></li>
                <li id="test2"><a href="about.html">testtest testtest</a></li>
                <li id="test3"><a href="#">test testtest testtest </a></li>
                <li id="test4"><a href="#">test</a></li>
                <li id="test5"><a href="#">testtes ttesttest</a></li>
                <li id="test6"><a href="#">test</a></li>
                <li id="test7"><a href="#">test</a></li>
            </ul>-->

Comments

Popular posts from this blog

Scroll After Fixed Navigation

Bootstrap CSS Customize with SCSS CSS

Best way to prevent page scrolling on drag (mobile)