View Single Post
Old 03-13-2009, 05:16 PM   PM User | #4
Eldarrion
Regular Coder

 
Join Date: Feb 2009
Location: Wheeling, IL
Posts: 358
Thanks: 5
Thanked 62 Times in 60 Posts
Eldarrion is on a distinguished road
Nope, no framework involved, looks like clean JS. Either way, as it seems, you are already assigning the class there with .className Now for the more interesting part... finding each element that is currently visible and hiding it:

Code:
<script type="text/javascript">
function display (category) {
    var whichcategory = document.getElementById(category);
    var showClass = "show";
   
    var all = document.getElementsByTagName('*');

    var shown = new Array();
    for (var e = 0; e < all.length; e++) {
        if (all[e].className == showClass)
            shown[shown.length] = all[e];
    }

    if (whichcategory.className == showClass)
        whichcategory.className = "hide";
    else {
        for (var i = 0; i < shown.length; i++)
            shown[i].className = "hide";
        whichcategory.className = showClass;
    }
}
</script>
Probably _not_ the best way to do it... and I'm not sure exactly how it will play out with nested locations, but I believe it can be modified to ignore elements that are parent elements of the one you're currently trying to show.
Eldarrion is offline   Reply With Quote
Users who have thanked Eldarrion for this post:
srlagarto (03-16-2009)