Skip to content

Instantly share code, notes, and snippets.

@passcod
Created December 7, 2012 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passcod/4232002 to your computer and use it in GitHub Desktop.
Save passcod/4232002 to your computer and use it in GitHub Desktop.
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<style>
nav#main a[data-current] { color: red; }
</style>
<nav id="main">
<a href="#!/">A</a>
<a href="#!/derp">B</a>
<a href="#!/herp">C</a>
</nav>
$(function() {
var doNavigate = function(section) {
section = section || window.location.href.split("#!/")[1] || "";
section = section.target === undefined ? "#!/" + section : section.target.hash;
$("nav#main a")
.removeAttr("data-current")
.filter("[href='"+ section +"']")
.attr("data-current", "");
};
$("nav#main").on("click", "a", doNavigate);
doNavigate();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment