I’m trying to build a tree with javascript, but I’m making some mistake in my code, and am not able to identify it.
Here is my javascript code:
[CODE]function tree_init(){
varTree = document.getElementById(“tree”)
varState = varTree.getElementsByTagName(“li”);
for(i=0;i<varState.length;i++){
varCity = varState.item(i).getElementsByTagName(“ul”);
if(varCity.length > 0) {
varCity.item(0).style.display = “none”;
varState.item(i).onclick = function() {
if(this.getElementsByTagName(“ul”).item(0).style.display == “none”){
this.getElementsByTagName(“ul”).item(0).style.display = “block”;
this.style.listStyleImage = “url(‘../images/tree_open.jpg’)”;
}
else
{
this.getElementsByTagName(“ul”).item(0).style.display = “none”;
this.style.listStyleImage = “url(‘../images/tree_close.jpg’)”;
}
}
}
}
}
If I expand the top level, it expands. But when I click on a second level, it closes the parent, whereas it should expand the second level. (It does expand the expand the 2nd level, but we can’t see it becoz it closes the top level).
Thank you, in advance
[QUOTE]