Okay, the LI element it is.
The start of the showUser function is a good place to put it.
function showUser(str) {
showActive(str);
...
}
Now to prepare for the showActive function:
The first thing you’ll need to do is to remove the “active” class from all of the list items. Why? Consider this scenario. The third item is currently active, then someone selects the last item. How is the scripting to know to remove the class from the third item?
The script doesn’t know which one was active previously, and solutions such as using getElementsByClassName are very unweildy due to requiring compatibility code for web browsers such as IE that don’t support it. The best solution is to remove the class from all of the items.
So, we need to put together a list of all list items. To get that list we can go up the parent elements from the clicked link, until we reach a UL element. To help prevent any scripting error, if we get to the BODY element we’ll stop processing things.
Once we get to the UL element, from there we can get all of the LI tag names, and then we can remove the active class from them. But first, don’t forget to also include the class handling functions
function hasClass(ele,cls) {
return ele.className.match(new RegExp('(\\\\s|^)'+cls+'(\\\\s|$)'));
}
function addClass(ele,cls) {
if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\\\s|^)'+cls+'(\\\\s|$)');
ele.className=ele.className.replace(reg,' ');
}
}
Now to get the list items, which is my next post.
Did you fix Cat 5 so that it’s id=“5” yet?