0
How would I make it when the user clicks a button, opens a div and changes the color of the button? Since I am using Bootstrap, I tried this way, but I could only open the div, but not change the button color:
Javascript
<script>
function mostrarDiv(valor)
{
var valor;
if(valor == 0)
{
document.getElementById('outros').style.display='block';
document.getElementById('categorias').style.display='none';
document.getElementById('btnOutros').className = 'btn btn-xlg btn-primary waves-effect waves-light';
}
if(valor == 1)
{
document.getElementById('outros').style.display='none';
document.getElementById('categorias').style.display='block';
document.getElementById('btnCategorias').className = 'btn btn-xlg btn-primary waves-effect waves-light';
}
}
</script>
Bootstrap
<button type="button" id="btnOutros" class="btn btn-xlg btn-inverse-primary waves-effect waves-light" onclick="mostrarDiv(0)"><i class="fas fa-users"></i> Outros</button>
<button type="button" id="btnCategorias" class="btn btn-xlg btn-primary btn-inverse-primary waves-effect waves-light" onclick="mostrarDiv(1)"><i class="fas fa-list-ol"></i> Categorias</button>
HTML
<div id="outros">
Conteúdo
</div>
<div id="categorias">
Conteúdo
</div>
It worked. Thank you Sam.
– user24136
Beautifully presented.
– MauroAlmeida