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; }
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
Post a Comment