PDA

View Full Version : Javascript to change a link's css class



Chris
11-18-2006, 07:06 AM
Is there a way with javascript to indicate the current menu location with css?

If self.url = link.href then link.href.cssclass = current?

Something automatic rather than manually coding something in.

KelliShaver
11-18-2006, 01:38 PM
Something like this should work.... just call it when the page loads.



function checkLinks() {
var anchors = document.getElementsByTagName('a');

for (var i=0; i<anchors.length; i++){
var anchor = anchors[i];

if (anchor.href == location.href){
anchor.className = "someClass";
}
}
}

Chris
11-18-2006, 02:38 PM
Thanks.... if it works its for the redesign of this site.