Created
October 2, 2012 01:38
-
-
Save stvedt/3815657 to your computer and use it in GitHub Desktop.
This file contains 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
$(document).ready(function(){ | |
var pageName = getPage(); | |
$('#nav a').each(function(){ | |
var $this = $(this); | |
var anchorHref = $this.attr('href'); | |
if( anchorHref == pageName) $this.addClass('current'); | |
}); | |
function getPage(){ | |
var loc = $(location).attr('href'); | |
var splitUrl = loc.split("/"); | |
var page = splitUrl[splitUrl.length - 1]; | |
page = (page =='') ? 'index.html' : page; | |
return page; | |
} | |
}); |
This file contains 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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>JS and HTML - Current Page</title> | |
<link href="style.css" rel="stylesheet" type="text/css" media="all" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script> | |
<script src="global.js"></script> | |
</head> | |
<body> | |
<h1>Home</h1> | |
<div id="nav"> | |
<a href="index.html">Home</a><br> | |
<a href="about.html">About</a><br> | |
<a href="contact.html">Contact</a> | |
</div> | |
</body> | |
</html> |
This file contains 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
@charset "UTF-8"; | |
.current{ | |
background-color:#3CF; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment