Ok, so I have a very long hierarchical list that expands and collapses. To make the maintenance easier, I wrote some javascript to do the following:
1) Add the id content# where # starts at 0 and increases by 1 for each UL tag that will later be used to expand and collapse parts of the list. [function addid]
2) Add a href to the expand and collapse toggle javascript to all the links that are used to expand and collapse the list. [function addid]
3) [function collapse] Works the button that will collapse the entire list.
4) [function expand] Works the button that will expand the entire list.
5) [function toggle] Works all of the links that expand and collapse parts of the list.
Here is a URL to my test site so you can see what I am talking about:
Here are the javascript functions for the page:
Now, this works perfectly and without errors in Chrome, Opera, Firefox and Safari. It does not work in IE. IE appears to be doing function addid ok, but nothing else works. It only gives the ambiguous error that an object was expected.
So, anyone more talented at this then me willing to give it a shot??
THANKS!!
1) Add the id content# where # starts at 0 and increases by 1 for each UL tag that will later be used to expand and collapse parts of the list. [function addid]
2) Add a href to the expand and collapse toggle javascript to all the links that are used to expand and collapse the list. [function addid]
3) [function collapse] Works the button that will collapse the entire list.
4) [function expand] Works the button that will expand the entire list.
5) [function toggle] Works all of the links that expand and collapse parts of the list.
Here is a URL to my test site so you can see what I am talking about:
Here are the javascript functions for the page:
Code:
function addid() {
var g = document.getElementsByName('treebranch');
for(var i=0; i<g.length; i++) { g[i].id = 'content' + i; };
var a = document.getElementsByName('treelink');
for(var i=0; i<a.length; i++) {a[i].href = 'javascript:toggle(\'content' + i + '\')'; };
}
function collapse() {
var i=0;
var g = document.getElementsByTagName('ul');
for (var i=0; i<g.length; i++) {
document.getElementById('content'+i).style.display = 'none';
}
}
function expand() {
var i=0;
var g = document.getElementsByTagName('ul');
for (var i=0; i<g.length; i++) {
document.getElementById('content'+i).style.display = 'block';
}
}
function toggle(list){
var listElementStyle=document.getElementById(list).style;
if (listElementStyle.display=="block"){
listElementStyle.display="none";
}
else{ listElementStyle.display="block";
}
}
Now, this works perfectly and without errors in Chrome, Opera, Firefox and Safari. It does not work in IE. IE appears to be doing function addid ok, but nothing else works. It only gives the ambiguous error that an object was expected.
So, anyone more talented at this then me willing to give it a shot??
THANKS!!