I have a navigation bar at the side of a page and want to highlight one of several entries depending on GET-parameters.
After a little Reading I came to this solution, but it does not seem to work:
in the .html:
<script type="text/javascript">
$(document).ready(highlight_me());
</script>
the JS functions:
function highlight_me() {
// ensure all links have class 'regular'
document.links.className = 'regular';
// determine which link to highlight
var id = 'home';
switch (querystring('view')) {
case "set":
id = 'settings';
break;
case "mc":
id = 'messages';
break;
default:
id = 'home';
}
// highlight link
document.getElementById(id).className = 'highlight';
}
function querystring(key) {
// extract GET-value for key
var re = new RegExp('(?:\\?|&)' + key + '=(.*?)(?=&|$)', 'gi');
var r = [], m;
while ((m = re.exec(document.location.search)) != null) r[r.length] = m[1];
return r;
}
the CSS classes:
a, a.regular, a:visited {
color: #f0ce96;
}
a:active, a:hover, a.highlight {
text-decoration: underline;
color: #ffeebb;
}
I'd be thankful for a hint that points me to where I go wrong, here.