2
The code below does not run on all browsers:
<button id="btn">
<img class=""
src="/img/icone-formation.png"
height="100%"
width="100%"
onclick="document.getElementById('f1').style.display ='initial';
document.getElementById('f2').style.display ='none';
document.getElementById('f3').style.display ='none';
document.getElementById('f4').style.display ='none';
document.getElementById('f5').style.display ='none';
document.getElementById('btn').setAttribute('id', 'press');">
</button>
<button id="btn">
<img class=""
src="/img/icone-formation.png"
height="100%"
width="100%"
onclick="document.getElementById('f2').style.display ='initial';
document.getElementById('f1').style.display ='none';
document.getElementById('f3').style.display ='none';
document.getElementById('f4').style.display ='none';
document.getElementById('f5').style.display ='none';
document.getElementById('btn').setAttribute('id', 'press');">
</button>
<button id="btn">
<img class=""
src="/img/icone-formation.png"
height="100%"
width="100%"
onclick="document.getElementById('f3').style.display ='initial';
document.getElementById('f1').style.display ='none';
document.getElementById('f2').style.display ='none';
document.getElementById('f4').style.display ='none';
document.getElementById('f5').style.display ='none';
document.getElementById('btn').setAttribute('id', 'press');">
</button>
<button id="btn">
<img class=""
src="/img/icone-formation.png"
height="100%"
width="100%"
onclick="document.getElementById('f5').style.display ='initial';
document.getElementById('f1').style.display ='none';
document.getElementById('f2').style.display ='none';
document.getElementById('f3').style.display ='none';
document.getElementById('f4').style.display ='none';
document.getElementById('btn').setAttribute('id', 'press');">
</button>
How can I do the same thing with pure CSS?
Easier to say what you want to do instead of just putting the code. This code you posted is not supposed to work anyway, because it is with errors. Suggested reading to better elaborate the question: [Ask] and MCVE. Maybe before these two links it is worth reading the [tour].
– Bacco
Therefore, it is through the button to change the displayed contents... It is working correctly, but it is not compatible with the desired browsers. Basically the code, selects an id of the range (F1 F2 F3 F4 F5) object of the respective id to be shown and hides the others. Where exactly is the error?
– user38475
one of the problems is you use the same ID on all buttons.
– Bacco
I advise to review all your code because the way you are programming is totally illogical. 1º each button of yours should execute a function and not a block of scripts. 2º if you have no more than 1 element with the same id. 3rd functions should be applied to buttons and not to images... and so on
– LeandroLuk