How to expand nested Bootstrap 4 Collapse from URL?
I have a nested Bootstrap 4 Collapse. The outer Collapse consists of Days, whereas the inner Collapse consists of Events, that take place on that particular day. It looks approximately like this...
<!-- HEADER DAY 1-->
<div data-toggle="collapse" data-target="#day-unixtimestamp1" role="button" aria-expanded="false" aria-controls="#day-unixtimestamp1" >
DAY ONE (e.g. October 25th, 2021)
</div>
<!-- BODY DAY 1 -->
<div class="body collapse" id="day-unixtimestamp1">
<!-- HEADER EVENT 1-->
<div data-toggle="collapse" data-target="#event-unixtimestamp1-event1" role="button" aria-expanded="false" aria-controls="#event-unixtimestamp1-event1" >
NAME EVENT 1
</div>
<!-- BODY EVENT 1 -->
<div class="body collapse" id="event-unixtimestamp1-event1">
...some content
</div>
<!-- HEADER EVENT 2-->
<div data-toggle="collapse" data-target="#event-unixtimestamp1-event2" role="button" aria-expanded="false" aria-controls="#event-unixtimestamp1-event2" >
NAME EVENT 2
</div>
<!-- BODY EVENT 2 -->
<div class="body collapse" id="event-unixtimestamp1-event2">
...some content
</div>
</div>
I use WordPress and custom code to load the days and events from the database and loop over them. That works fine so far.
After a user creates a new event through submitting a form, he should be redirected to the page with the nested Bootstrap 4 Collapse and both sould be open: the Collapse of the new Event and the Collapse of associated Day.
I can expand the Event with the following URL: https://website.de/nested-collapse-page/#event-unixtimestamp1-event1
and the code below...
<script>
jQuery($ => {
if (window.location.hash) {
var hash = window.location.hash;
$(hash).collapse('show');
$('html, body').animate({
scrollTop: $(hash).offset().top - 180
}, 500 );
}
});
</script>
But I am a bit clueless how I open the acssociated Day too... I'm very gratefull for hints : )