Hey there!
I received this code from a friend who was trying to modify the switch buttons. I made some changes so that each button can now change the state of two separate elements when pressed. Here's the altered code:
function toggleClass(ev){
var el = document.querySelector(".pressed");
var fro = document.querySelector(".visible"); <--line added
el.className = 'notpressed';
ev.target.className = 'pressed';
fro.className = 'notvisible'; <--line added
ev.target.className = 'visible'; <--line added
}
span{
cursor:pointer;
padding:10px;
border:1px solid #FCFCFC;
}
.notpressed{
background:#CCC;
}
.pressed{
background: #DFF789;
}
.visible{
display:block;
}
.notvisible{
display: none;
}
<span id="but1" class="pressed" onclick="toggleClass(event);">BUTTON 1</span>
<span id="but2" class="notpressed" onclick="toggleClass(event);">BUTTON 2</span>
<div id="elem1">hello<div>
<div id="elem2">bye<div>
However, I'm facing an issue as it's not working as expected. Can you help me figure out what I'm missing?
Thanks in advance!