Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
|
Code:
$("#nav a").each(function() {
if(this.href == window.location || this.href == document.location.protocol + "//" + window.location.hostname + window.location.pathname)
$(this).addClass("active");
});
or, you could use CSS attribute selectors. I think this will work:
Code:
var path = document.location.protocol + "//" + window.location.hostname + window.location.pathname;
$("#nav a[href=" + window.location + "], #nav a[href=" + path + "]").addClass("active");
It is important to note that paths contained inside of any href property always manifest as absolute paths in JavaScript, no matter how they are expressed in the HTML.
Last edited by wayfarer07; 04-14-2009 at 02:18 PM..
|