javascript - Different style for the current link when I clicked -


can me code? want put different style of current link, had selected. hyperlinks not go different pages, refers current page.

here code:

html

<nav id="nav"> <ul> <li class="current"><a href="#top" id="top-link" ><span>home</span></a></li> <li><a href="#portfolio" id="portfolio-link"><span>portfolio</span></a></li> <li><a href="#about" id="about-link"><span>about</span></a></li> </ul> </nav> 

css

#nav ul li a:hover  {   color:#fff;   background-color:#333;  }   #nav ul li a:active  {  color:#fff;  background-color:#333;  } 

fiddle demo here

you can change .current class on click using jquery code.

var links = $('#nav li'); links.click(function() {  $(this).parent().find(".current").removeclass('current'); $(this).addclass('current');  }); 

check demo.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -