简体   繁体   中英

navigation css style is not working

yesterday I have posted this ..but no one answers.

I have jsfiddle this code..I want to color navigation button when it is active..It is working here..but when I put this jsfiddle code to my project it is colored until the page is loading,then it is going to previous color.if I use # then it is working..

in my code I have

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>

  $(document).ready(function(e) {   
        $("ul li a").click(function(){
            $("ul li a").removeClass("active");
            $(this).addClass("active");
        });
    });

</script>

and the jsfiddle html and css code..what am I doing wrong?pls guys suggest me.

Yes, as @Arun has commented on your question. javascript action is only on the DOM elements that you are currently on.

But the solution for you is via jquery cookie . You can save your clicked element on jquerycookie and can retrieve on next page. For detail please read the jquerycookie usage

Update : Try this jQuery('a[href="' + this.location.pathname + '"]').addClass('active'); if your link is <a href="/blog.php">x</a>

And try jQuery('a[href="' + this.location.href + '"]').addClass('active'); if your link is <a href="https://www.absolutepath.com/blog.html">x</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM