Hi. I am trying to write a function to write a navigation as an [B]unordered list
I would like a two tiered navigation, but not sure what data structure to use.
I got a one level navigation working by using an object as a sort of hash.
2 things I would love suggestions for:
1) The method nav.print() takes a parameter which when supplied adds a current class to the <a> tag. But can I make it so that if the name of that nav item changes in the items object, I won’t have to change the parameter name in the nav.print method call?
2) Can anyone suggest a data structure to support an unliminted number of sub nav items for each nav item?
[CODE] var nav = {
navContainer : $(‘nav’), //getElementById
items : {
“Home”: ‘index.php’,
“Resources”: ‘resources.php’
},
print: function(currName){
var frag = document.createDocumentFragment();
var ul = document.createElement(‘ul’);
for (var name in this.items){
var item = document.createElement(‘li’);
var link = document.createElement(‘a’);
var str = document.createTextNode(name);
link.setAttribute(‘href’, this.items[name]);
if (currName == name) link.setAttribute(‘class’,’current’);
link.appendChild(str);
item.appendChild(link);
ul.appendChild(item);
}
frag.appendChild(ul);
this.navContainer.appendChild(frag);
}
}
nav.print(‘Home’); //create the nav with ‘Home’ as the current item
[URL=”http://www.cohencentral.com/projects/js_nav/”]http://www.cohencentral.com/projects/js_nav/
Any advice is appreciated.