var loc = document.location.toString(); var location_parts = loc.split('/'); this_loc = location_parts[location_parts.length-1]; if(this_loc == '' || this_loc == undefined) { $('#nav li a[href=\'index.php\']').addClass('selected'); } else { $('#nav li a[href=\'' + this_loc + '\']').addClass('selected'); }