I have a challenge with creating toggle buttons that require specific functions:
1) Display content on the first click (this is working)
2) Conceal content when another button is clicked (this is also working)
3) Hide content on the second click (this is not working as intended)
Currently, clicking the same button twice causes the content to slide up and then immediately down, resulting in a jittery experience. Is there a solution to make all 3 functions work seamlessly? Removing the line "$(".assortiment").slideUp();" resolves the jumping issue but it interferes with function 2...
function assortiment(e){
var assortimentid = e.id + "__js";
if ($("#" + assortimentid).display = "block"){
$(".assortiment").slideUp();
$("#" + assortimentid).slideToggle();
} else if ($("#" + assortimentid).display = "none"){
$("#" + assortimentid).slideToggle();
}
}
.assortiment {
display: none;
}
.btn {
border: 1px solid black;
border-radius: 10px;
padding: 10px;
width: 100px;
margin: 5px;
background-color: lightblue;
}
.btn:hover {
cursor: pointer
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn" id="section1" onclick="assortiment(this)">Section 1</div>
<div class="btn" id="section2" onclick="assortiment(this)">Section 2</div>
<div class="btn" id="section3" onclick="assortiment(this)">Section 3</div>
<div class="assortiment" id="section1__js">
<p>SOME CONTENT 1</p>
<p>Lorem ipsum dolor sit amet, aliquip apeirian dissentiunt ex pro. Ad choro facilis offendit mel, et quo quot democritum. Aliquip quaestio periculis ad eam, legere altera reprehendunt eu his. Cu has virtute pericula definitionem, cu facete conclusionemque has, cu errem accusamus duo.
</p>
</div>
<div class="assortiment" id="section2__js">
<p>SOME CONTENT 2</p>
<p>Lorem ipsum dolor sit amet, aliquip apeirian dissentiunt ex pro. Ad choro facilis offendit mel, et quo quot democritum. Aliquip quaestio periculis ad eam, legere altera reprehendunt eu his. Cu has virtute pericula definitionem, cu facete conclusionemque has, cu errem accusamus duo.
</p>
</div>
<div class="assortiment" id="section3__js">
<p>SOME CONTENT 3</p>
<p>Lorem ipsum dolor sit amet, aliquip apeirian dissentiunt ex pro. Ad choro facilis offendit mel, et quo quot democritum. Aliquip quaestio periculis ad eam, legere altera reprehendunt eu his. Cu has virtute pericula definitionem, cu facete conclusionemque has, cu errem accusamus duo.
</p>
</div>