$(document).ready(function(){ /* Check if url contains 'index.html'. If not then add it to the url. */ var curr_url = ($.url.attr("path").search(/index.html/i) >= 0) ? $.url.attr("path") : $.url.attr("path") + "index.html"; var parent_url = ""; var notthere = 0; while (notthere < 1) { //If topmost URL, then parent and current url is the same, otherwise generate parent url. parent_url = (curr_url == $("div#leftnav ul a:first").attr("href")) ? curr_url : curr_url.substr(0, curr_url.substr(0, curr_url.lastIndexOf("/")).lastIndexOf("/")+1) + "index.html"; //If the current url doesn't exist in the leftnav, then set it equal to its parent if ($("div#leftnav ul").find("li a[href^='"+curr_url+"']").length == 0) { curr_url = parent_url; } //set variable to length (occurences of the current url) notthere = $("div#leftnav ul").find("li a[href^='"+curr_url+"']").length; } //Adding classes to relevant