Javascript code refactoring and assessment
- by neitony
I'm using javascript to toggle the display state of some objects based on the time of day. A sample of the code is given below. I was wondering if anyone could give a suggestion as to how I can refactor this code while at the same time improving the logic.
switch(tcode) {
case 'eur' : eur.setAttribute('style', 'display:block; opacity:0.5');
us.style.display = 'none';
asia.style.display = 'none';
us_inactive.style.display = 'block';
asia_inactive.style.display = 'block';
break;
case 'us' : us.style.display = 'block';
eur.style.display = 'none';
asia.style.display = 'none';
eur_inactive.style.display = 'block';
asia_inactive.style.display = 'block';
break;
case 'asia' : asia.setAttribute('style', 'display:block; opacity:0.5');
us.style.display = 'none';
eur.style.display = 'none';
eur_inactive.style.display = 'block';
us_inactive.style.display = 'block';