3
I wonder how I can use javascript to change the color of the button after it has been clicked; that is, below the code has 2 formats. If you click the A1 format, the button where the div is will change color and will be changed indicating that the format is selected; then, if you click the other button, it will disable A1 and activate the A2 color. How can I do this using javascript, and this should be done with multiple items?
<div onclick="document.getElementById('A1').style.display='block';document.getElementById('A2').style.display='none';">Formato 1</div><div onclick="document.getElementById('A1').style.display='block';document.getElementById('A2').style.display='none';">Formato 2</div>
<div id="A1" style="display:block;">Conteudo oculto 1</div>
<div id="A2" style="display:none;">Conteudo oculto 1</div>
Thanks so much for the solution with the code below now just to finish how I can make the code below work with several items at the same time because I need it to work with several items on the same page.
<div>Item 1</div>
<div id="formato1">Formato 1</div>
<div id="formato2">Formato 2</div>
<div id="A1" style="display:block;">Conteudo oculto 1</div>
<div id="A2" style="display:none;">Conteudo oculto 2</div>
<div>Item 2</div>
<div id="formato1">Formato 1</div>
<div id="formato2">Formato 2</div>
<div id="A1" style="display:block;">Conteudo oculto 1</div>
<div id="A2" style="display:none;">Conteudo oculto 2</div>
<div>Item 3</div>
<div id="formato1">Formato 1</div>
<div id="formato2">Formato 2</div>
<div id="A1" style="display:block;">Conteudo oculto 1</div>
<div id="A2" style="display:none;">Conteudo oculto 2</div>
Have you put an example in a plunkr?
– mutlei