1
Hello, everybody!
I would like to know the correct way to write this simple Javascript excerpt:
By clicking on the div ". plus", all the Divs ". contents" are expanding.
What is the correct writing semantics so that a click on the div ". plus" of the id="languages" does not execute the action on the div ". id="code" and "frameworks" content and vice versa.
$(".mais").click(function() {
$(".mais").fadeOut()
$(".menos").css("display", "flex")
$(".conteudo").css("max-height", "60rem")
});
$(".menos").click(function() {
$(".menos").fadeOut()
$(".mais").css("display", "flex")
$("#conhecimentos .conteudo").css("max-height", "0")
});
<div id="linguagens">
<div class="titulo">
<h2>Linguagens</h2>
<div class="expand">
<div class="mais">
</div>
<div class="menos">
</div>
</div>
</div>
<div class="conteudo">
<p>exemplo
<br>exemplo
<br>exemplo
<br>exemplo</p>
</div>
</div>
<div id="codigos">
<div class="titulo">
<h2>Codigos</h2>
<div class="expand">
<div class="mais">
</div>
<div class="menos">
</div>
</div>
</div>
<div class="conteudo">
<p>exemplo
<br>exemplo
<br>exemplo
<br>exemplo</p>
</div>
</div>
<div id="frameworks">
<div class="titulo">
<h2>Frameworks</h2>
<div class="expand">
<div class="mais">
</div>
<div class="menos">
</div>
</div>
</div>
<div class="conteudo">
<p>exemplo
<br>exemplo
<br>exemplo
<br>exemplo</p>
</div>
</div>
Excellent contribution, Sergio! Thank you very much. But the main doubt is how to make the action be performed in only 01 div ". content" and not at all.
– Will
@Will is what my code does. It uses the relationship between elements in the DOM to act on only one
.conteudo
and not all. You tested my example?– Sergio
@Will, I respect you taking the answer that best solves your problem. But the answer you have accepted will give a lot of headache if HTML changes 1 millimeter... is too customized and is a headache just to see...
– Sergio