1
Staff I am doing the following function on a Web Site: XXX-A | XXX-B | XXX-C | XXX-D When one clicks on the XXX-A only the DIV with A content will appear and so on... But I managed to make the content appear but I can’t make the others disappear, follows below the code:
function MudarMethod() {
const content01 = document.getElementById('content01');
if(document.GetElementById('content2').style.display == 'block')
document.GetElementById('content3').style.display == 'block')
document.GetElementById('content4').style.display == 'block')
{
document.GetElementById('content2').style.display = 'none'
document.GetElementById('content3').style.display = 'none'
document.GetElementById('content4').style.display = 'none'
content01.style.display = 'block'
}
}
document.getElementById('button1').addEventListener('click', () => MudarMethod());
#content01 {
display: none;
}
#content02 {
display: block;
}
#content03 {
display: none;
}
#content04 {
display: none;
}
<div class="background-content">
<div class="align-content">
<h1>Métodos de ensino</h1>
<div id="methodlearn">
<button id="button1">XXX</button>
<button id="button2">XXX</button>
<button id="button3">XXX</button>
<button id="button4">XXX</button>
<div id="content01">Conteúdo 01</div>
<div id="content02">Conteúdo 02</div>
<div id="content03">Conteúdo 03</div>
<div id="content04">Conteúdo 04</div>
</div>
</div>
</div>
I put the display:block in content 2 to just take the test and see if it’s catching.
Personal thank you!
Sam, I found your method of explanation amazing congratulations! for(var el of Childs) { if(this == el) break; index++; } What did you mean by if(this == el)? Is this Childs? I am very grateful for your comment
– Castiel
Thanks. This is the button that called the onclick event. In this case I check if the button that called the event is equal to one of the buttons in the collection.
– Sam