0
I want javascript to recognize which button I press, when I press button A to show div A , and when I press button B to show div B, the two Divs cannot appear together.
The code I’m making right now is like this:
<input type="button" id="A" required="" value="A" onclick="Mudarestado()"/>
<input type="button" id="B" required="" value="B" onclick="Mudarestado()"/>
<div class="row" id="displayA" style="display:none;">
<p>A</p>
</div>
<div class="row" id="displayB" style="display:none;">
<p>B</p>
</div>
</div>
<script>
function Mudarestado(el) {
var btn // deve receber o valor do botão A ou do botao B
console.log(btn);
if (btn == "A"{
var display = document.getElementById('displayA').style.display;
if(display == "none")
document.getElementById('displayA').style.display = 'block';
else
document.getElementById('displayA').style.display = 'none';
} if else ( btn == "B" ){
var display = document.getElementById('displayB').style.display;
if(display == "none")
document.getElementById('displayB').style.display = 'block';
else
document.getElementById('displayB').style.display = 'none';
}
}
</script>
how I would change the code that way then?
– Thiago Luiz Ferreira Tavares
includes the example code @Thiagoluizferreiratavares
– Alexandre Cavaloti