Okay so I inherited a site from a previous developer to make some upgrades to. One thing that is annoying me (though not the client) is that a single tab is always the “.selected” tab, even when it is not actually selected. Technically I think it is “selected default”.
Site is rooferanchorage.com.
I tried just removing default from the last section in the .js but no effect. I am a total javascript illiterate as you can probably tell. I believe this is the relevant code – any suggestions on how I can make the selected class work correctly?
isSelected:function(menuurl){
var menuurl=menuurl.replace("http://"+menuurl.hostname, "").replace(/^\//, "")
return (tabdropdown.currentpageurl==menuurl)
},
init:function(menuid, dselected){
this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes
var menuitems=document.getElementById(menuid).getElementsByTagName("a")
for (var i=0; i<menuitems.length; i++){
if (menuitems[i].getAttribute("rel")){
var relvalue=menuitems[i].getAttribute("rel")
document.getElementById(relvalue).firstlink=document.getElementById(relvalue).getElementsByTagName("a")[0]
menuitems[i].onmouseover=function(e){
var event=typeof e!="undefined"? e : window.event
tabdropdown.dropit(this, event, this.getAttribute("rel"))
}
}
if (dselected=="auto" && typeof setalready=="undefined" && this.isSelected(menuitems[i].href)){
menuitems[i].parentNode.className+=" selected default"
var setalready=true
}
else if (parseInt(dselected)==i)
menuitems[i].parentNode.className+=" selected default"
}
}
On lines 72-73 of your source code is the following:
Referencing the code in your question, you can see the condition in the
initmethod which readsif (dselected=="auto" ...and will apparently check thehrefof the anchor inside the menu item against the URL to see if it’s the tab that should be selected.Currently your code is passing
3which means it’ll be the 4th tab always – a zero-based index0,1,2,3which would explain why “Commercial” is always selected.Answer, try changing that
3to"auto", or, if you are using static html files (for example if residential.html is an actual html file) try changing the integers to represent the tabs that should be selected for each one. Residential would be2, for example.