Reputation: 276
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"
}
}
Upvotes: 1
Views: 184
Reputation: 77966
On lines 72-73 of your source code is the following:
//SYNTAX: tabdropdown.init("menu_id", [integer OR "auto"])
tabdropdown.init("colortab", 3)
Referencing the code in your question, you can see the condition in the init
method which reads if (dselected=="auto" ...
and will apparently check the href
of 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 3
which means it'll be the 4th tab always - a zero-based index 0,1,2,3
which would explain why "Commercial" is always selected.
Answer, try changing that 3
to "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 be 2
, for example.
Upvotes: 1