I'm trying to get JS to swap the style class on my webpage. The following almost works. Basically it is initiated using 'onClick' in the HTML. The class is (in most cases) set to 'hide'. You click on it and the JS changes the class to 'show'. This works. Problem is, if I set the initial html to 'show' the JS doesn't work until the object is clicked more than once.
menu_status = new Array();
function showHide(target){
var switch_id = document.getElementById('submenu_'+target);
if(menu_status['submenu_'+target] == 'show') {
switch_id.className = 'hide';
menu_status['submenu_'+target] = 'hide';
}else{
switch_id.className = 'show';
menu_status['submenu_'+target] = 'show';
}
}
menu_status = new Array();
function showHide(target){
var switch_id = document.getElementById('submenu_'+target);
if(menu_status['submenu_'+target] == 'show') {
switch_id.className = 'hide';
menu_status['submenu_'+target] = 'hide';
}else{
switch_id.className = 'show';
menu_status['submenu_'+target] = 'show';
}
}