I get an odd reaction when the for loop(s) runs in selected(). The goal is to access previously selected items and change their className to child. With the for loop taken out, everything works as expected. Padding and other (fascinating) issues can be seen in IE, Netscape, Firefox and Opera.
<html>
<body>
<script language=”javascript”>
<!–
function navagation(pValue){
if(document.getElementById(pValue).style.display==”none”){
document.getElementById(pValue).style.display=””
}else{
document.getElementById(pValue).style.display=”none”;
}
}
function selected(pValue){
// — problem area — //
if(document.layers){
for(var i=0; i<document.layers.length-1; ++i){
if(document.layers[i].className=”selected_child”){
document.layers[i].className=”child”;
//alert(i);
}
}
}else{
for(var i=0; i<document.all.length-1; ++i){
if(document.all[i].className=”selected_child”){
document.all[i].className=”child”;
//alert(i);
}
}
}
// — problem area — //
document.getElementById(pValue).className=”selected_child”;
}
–>
</script>
<style>
<!–
.child{
text-decoration: none;
padding-left: 12px;
color: #acacac;
}
.child:hover{
padding-left: 12px;
color: #000000;
background-image: url(navagation_arrow.jpg);
background-color: #ffffff;
background-position: left top;
background-repeat: no-repeat;
}
.selected_child{
text-decoration: none;
padding-left: 12px;
color: #000000;
background-image: url(navagation_arrow.jpg);
background-color: #ffffff;
background-position: left top;
background-repeat: no-repeat;
}
–>
</style>
<table width=”200″ border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”100%” id=”main0″ onClick=’navagation(“main0_sub”);’ style=”color: #EF3E34; padding-left: 12px;”>Parent0</td>
</tr><tr>
<td width=”100%” id=”main0_sub” style=”display: none;”>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr><td width=”100%”><a id=”Parent0_Child0″ class=”child” onclick=’selected(“Parent0_Child0″);’ href=”#”>Parent0_Child0</a></td></tr>
<tr><td width=”100%”><a id=”Parent0_Child1″ class=”child” onclick=’selected(“Parent0_Child1″);’ href=”#”>Parent0_Child1</a></td></tr>
<tr><td width=”100%”><a id=”Parent0_Child2″ class=”child” onclick=’selected(“Parent0_Child2″);’ href=”#”>Parent0_Child2</a></td></tr>
<tr><td width=”100%”><a id=”Parent0_Child3″ class=”child” onclick=’selected(“Parent0_Child3″);’ href=”#”>Parent0_Child3</a></td></tr>
</table>
</td>
</tr><tr>
<td id=”main1″ style=”color: #EF3E34; padding-left: 12px;”>Parent1</td>
</tr>
</table>
</body>
</html>