I have a flexbox-container that contains multiple details-elements with flex-wrap behavior. My goal is to have a details-element move below the other elements within the container when it is opened.
For example, I want it to go from this initial layout:
to this rearranged layout:
Any subsequent open details should also jump to the last position in the container.
So far, I've attempted to change the order of the clicked details-element using JavaScript/jQuery:
$('details').click(function (event) {
this.style.order = "2";
$('details').not(this).style.order = "1";
});
.container {
display: flex;
flex-wrap: wrap;
}
details {
order: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<details>
<summary>
First Details
</summary>
<p>Some details</p>
</details>
<details>
<summary>
Second Details
</summary>
<p>Some details</p>
</details>
<details>
<summary>
Third Details
</summary>
<p>Some details</p>
</details>
<details>
<summary>
Fourth Details
</summary>
<p>Some details</p>
</details>
<details>
<summary>
Fifth Details
</summary>
<p>Some details</p>
</details>
</div>
Should I assign a class to the details-elements and target them differently? Or is there another method to achieve my desired effect?