-1
let botao1 = document.getElementById('botao1');
let imagemcentro = document.getElementById('imagemcentro');
let conteudo1 = document.getElementById('conteudo_1');
botao1.addEventListener('click', function() {
if (imagemcentro) {
imagemcentro.style.display = 'none';
conteudo1.classList.add('aparecer');
} else {
imagemcentro.style.display = 'flex';
}
});
#imagemcentro {
display: flex;
}
.conteudotodos {
visibility: hidden;
}
.aparecer {
visibility: visible;
}
<!DOCTYPE html>
<html>
<head>
<title>sub</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="block1">
<div class="barramento">
<button id="botao1">Saiba mais</button>
</div>
</div>
<div class="block2">
<div class="barramento2">
<button id="botao2">Saiba mais</button>
</div>
</div>
<div class="block3">
<div class="barramento3">
<button id="botao3">Saiba mais</button>
</div>
</div>
<!-- Conteudo -->
<div class="centro">
<div id="imagemcentro">
<h1>IMAGEM</h1>
</div>
<div id="conteudo_1" class="conteudotodos">
<div class="texto">
<h1>Exemplo1</h1>
</div>
</div>
<div id="conteudo_2" class="conteudotodos">
<div class="texto">
<h1>Exemplo2</h1>
</div>
</div>
<div id="conteudo_3" class="conteudotodos">
<div class="texto">
<h1>Exemplo3</h1>
</div>
</div>
<script type="text/javascript" src="sub.js"></script>
</body>
</html>
Thank you very much for your explanation, it will help me a lot, just a question, when the content1 enters the image is replaced, for me to do in all the contents and appear only 1 content, always replacing the previous one, as could be done?
– Magnus Froes
You can change the instruction
div.classList.add('aparecer');
fordiv.classList.toggle('conteudotodos');
. The functiontoggle
will look in the element class if there is any value compatible with what was reported, if it is, it removes, if it is not, it adds.– Victor Carnaval
Thank you very much!
– Magnus Froes