Created
June 22, 2010 21:16
-
-
Save jcutrell/449103 to your computer and use it in GitHub Desktop.
Add current class to links
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
//works only with static urls, like /home.html, etc | |
function lockit(someActiveClass){ | |
var href = window.location.href | |
var split = href.split('/'); | |
if (split[split.length-1] == "") { | |
var urlend = split[split.length-2] | |
} else { | |
var urlend = split[split.length-1] | |
} | |
var a = document.body.getElementsByTagName("a"); | |
for (var i = 0; i< a.length; i++){ | |
var asplit = a[i].href.split('/'); | |
if (asplit[asplit.length-1]) { | |
var aurlend = asplit[asplit.length-2] | |
} else { | |
var aurlend = asplit[asplit.length-1] | |
} | |
if (aurlend == urlend || aurlend.split('.')[0] == urlend.split('.')[0]{ | |
var yourClass = a[i].className + " " + someActiveClass; | |
a[i].setAttribute("class", yourClass) | |
a[i].setAttribute("className", yourClass); | |
} | |
} | |
} | |
lockit("superAwesomeClassname"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment