Open first group, then the next..slideToggle()
I'm trying to show or collapse everything from dayhead to the next dayhead while leaving daytrip_nfo collapsed until clicking on one of the daytrip headers. Then if another daytrip is clicked on, collapse the first and show
this (current one clicked on).
Here's my html.
- <div class="earningsTbl u-full-width">
- <div class="dayhead row">
- <div class="six columns">Wednesday, Nov 16 (11 Calls)</div>
- <div class="rte six columns">Day Total $283.00</div>
- </div>
- <div class="daytrip row" style="display: block;">
- <div class="one column"> </div>
- <div class="six columns">Trip ID: 126</div>
- <div class="rte five columns">Trip Total $12.00 ↠</div>
- </div>
- <div class="daytrip_nfo row" style="display: block;">
- <div class="two columns"> </div>
- <div class="four columns">StD to Jackson <br>Miles: 3.74</div>
- <div class="four columns">Wait Time: 0:01:45 <br>Extra Pax/Stop: 0/0</div>
- </div>
- <div class="daytrip row" style="display: block;">
- <div class="one column"> </div>
- <div class="six columns">Trip ID: 127</div>
- <div class="rte five columns">Trip Total $20.00 ↠</div>
- </div>
- <div class="daytrip_nfo row" style="display: block;">
- <div class="two columns"> </div>
- <div class="four columns">Ridgeland to Ridgeland <br>Miles: 3.39</div>
- <div class="four columns">Wait Time: 0:01:59 <br>Extra Pax/Stop: 0/0</div>
- </div>
- <div class="dayhead row">
- <div class="six columns">Thursday, Nov 17 (12 Calls)</div>
- <div class="rte six columns">Day Total $359.70</div>
- </div>
- <div class="daytrip row">
- <div class="one column"> </div>
- <div class="six columns">Trip ID: 137</div>
- <div class="rte five columns">Trip Total $20.00 ↠</div>
- </div>
- <div class="daytrip_nfo row">
- <div class="two columns"> </div>
- <div class="four columns">Flowood to Jackson <br>Miles: 8.25</div>
- <div class="four columns">Wait Time: 0:02:00 <br>Extra Pax/Stop: 0/0</div>
- </div>
- <div class="daytrip row">
- <div class="one column"> </div>
- <div class="six columns">Trip ID: 138</div>
- <div class="rte five columns">Trip Total $128.00 ↠</div>
- </div>
- <div class="daytrip_nfo row">
- <div class="two columns"> </div>
- <div class="four columns">Baptist to Forest <br>Miles: 49.13</div>
- <div class="four columns">Wait Time: 0:25:00 <br>Extra Pax/Stop: 0/0</div>
- </div>
- </div>
Here is the jquery code I'm struggling with.
- $('.dayhead').on('click', this, function() {
- var rowsCollapse = $(this).nextUntil('.dayhead');
- $(rowsCollapse).slideToggle();
- });
- $('.daytrip').on('click', this, function() {
- var rowsCollapse = $(this).nextUntil('.daytrip');
- $(rowsCollapse).slideToggle();
- });
The current document ready state starts correctly with all divs between each element with .dayhead collapsed.
When clicking on an element with the .dayhead class, it does toggle the elements' display until the next element with the .dayhead class, but also all elements with .daytrip_nfo. It glitches when you click on one of the elements with the .daytrip class then clicking on the previous element with .dayhead class.
I hope I explained that correctly.
I've tried every iteration of the code I can think of but still not nailing it.
Any help would be appreciated. Thanks in advance.