jquery - How to change color of hyperlink after click on it and stayed colored after reloading page? -


i have hyperlinks in drop-down-menu , want change color of hyperlink when click on that. code works, when link point page (= reloading page), color-changes disappear, doesn't work.

example:

1. <a href="#">this works</a> 2. <a href="/contact">doesn't work</a> 

my code enter link description here

html

<div id="menu">     <li><a href="#">item1</a>         <div class="submenu">             <a href="#">subitem1</a>               <a href="#">subitem2</a>                   </div>     </li>     <li><a href="#">item2</a></li>     <li><a href="#">item3</a></li>     <li><a href="#">item4</a></li> <li><a href="#">item5</a></li> </div> 

jquery

$(function(){     $("#menu a").bind("click", function(){         $("#menu a").removeclass("menucsslbl");         $(this).addclass("menucsslbl");     }); }); 

another workaround (i think can use it) use css :active. comment js code , try this:

#menu a:link { color: blue; } /** link */ #menu a:visited { color: purple; } /** visited, looking */ #menu a:hover { text-decoration: underline; } /** onhover */ #menu a:active { color: #666; } /** onmousedown */ 

you can set pseudo selectors each anchor separately, can useful in case.

remember if user deletes navigate history, :visited elements cleaned.

and yes, other workaround use cookies or localstorage, depending needs.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -