+ 1

J.S switch - help: Can you do DOM with switch,

Can we do DOM, with switch, Let's say we have <div id = "elm1"> 111111 </div> <div id = "elm2> 22222 </div> Start code with this: var a; var b; switch (new Date().get Day()){ case 0: .... } When It's Sunday (case 0): elm1 needs to display block, elm2 need to display none; When It's Monday (case 1): elm1 needs to display none, elm2 needs to display block; (If you can, please start with the starer code I gave you at top: var (1st var); var (2nd var); switch(new Date().get Day()){ case 0: }

23rd Jun 2019, 4:31 AM
Ginfio
Ginfio - avatar
2 ответов
+ 7
The above approach seems quite well. Where's the problem?
23rd Jun 2019, 5:33 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 3
M. Watney , I put it on words, but i couldn't turn my words into code. my real questipn should be ' how to have miltiple expressions in one case?' but now i figured it out: using comma. case 0: var a: doc...ById("elm1").style.dusplay="block") , doc...ById("elm2").style.display="none"; break; case 1: //Same thing for 1, but opposite of 0 (flip none and block). Yeah, anyways i figured it out, Thanks btw.✔️
23rd Jun 2019, 5:42 AM
Ginfio
Ginfio - avatar