Last active
May 1, 2016 16:58
-
-
Save ralhamami/09c359fd8b4f36a0e83212405b29d24a to your computer and use it in GitHub Desktop.
Navbar Active Link Highlighting on Simple Single Page Application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <nav class="navbar navbar-inverse navbar-fixed-top"> | |
| <div class="container-fluid"> | |
| <div class="navbar-header"> | |
| <a class="navbar-brand" href="#">Rayan Al-Hammami</a> | |
| </div> | |
| <ul class="nav navbar-nav navbar-right"> | |
| <li><a href="#">Home</a></li> | |
| <li><a href="#1">About</a></li> | |
| <li><a href="#2">Portfolio</a></li> | |
| <li><a href="#3">Contact</a></li> | |
| </ul> | |
| </div> | |
| </nav> | |
| <div id="1"></div> | |
| <div id="2"></div> | |
| <div id="3"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(".nav li a").on("click", function(){ | |
| $(".nav").find(".active").removeClass("active"); | |
| $(this).parent().addClass("active"); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .nav .active>a{ | |
| background: red !important; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment