Open first group, then the next..slideToggle()

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.

  1. <div class="earningsTbl u-full-width">

  2.   <div class="dayhead row">
  3.     <div class="six columns">Wednesday, Nov 16 (11 Calls)</div>
  4.     <div class="rte six columns">Day Total $283.00</div>
  5.   </div>
  6.   <div class="daytrip row" style="display: block;">
  7.     <div class="one column">&nbsp;</div>
  8.     <div class="six columns">Trip ID: 126</div>
  9.     <div class="rte five columns">Trip Total $12.00 ↠</div>
  10.   </div>
  11.   <div class="daytrip_nfo row" style="display: block;">
  12.     <div class="two columns">&nbsp;</div>
  13.     <div class="four columns">StD to Jackson <br>Miles: 3.74</div>
  14.     <div class="four columns">Wait Time: 0:01:45 <br>Extra Pax/Stop: 0/0</div>
  15.   </div>
  16.   <div class="daytrip row" style="display: block;">
  17.     <div class="one column">&nbsp;</div>
  18.     <div class="six columns">Trip ID: 127</div>
  19.     <div class="rte five columns">Trip Total $20.00 ↠</div>
  20.   </div>
  21.   <div class="daytrip_nfo row" style="display: block;">
  22.     <div class="two columns">&nbsp;</div>
  23.     <div class="four columns">Ridgeland to Ridgeland <br>Miles: 3.39</div>
  24.     <div class="four columns">Wait Time: 0:01:59 <br>Extra Pax/Stop: 0/0</div>
  25.   </div>

  26.   <div class="dayhead row">
  27.     <div class="six columns">Thursday, Nov 17 (12 Calls)</div>
  28.     <div class="rte six columns">Day Total $359.70</div>
  29.   </div>
  30.   <div class="daytrip row">
  31.     <div class="one column">&nbsp;</div>
  32.     <div class="six columns">Trip ID: 137</div>
  33.     <div class="rte five columns">Trip Total $20.00 ↠</div>
  34.   </div>
  35.   <div class="daytrip_nfo row">
  36.     <div class="two columns">&nbsp;</div>
  37.     <div class="four columns">Flowood to Jackson <br>Miles: 8.25</div>
  38.     <div class="four columns">Wait Time: 0:02:00 <br>Extra Pax/Stop: 0/0</div>
  39.   </div>
  40.   <div class="daytrip row">
  41.     <div class="one column">&nbsp;</div>
  42.     <div class="six columns">Trip ID: 138</div>
  43.     <div class="rte five columns">Trip Total $128.00 ↠</div>
  44.   </div>
  45.   <div class="daytrip_nfo row">
  46.     <div class="two columns">&nbsp;</div>
  47.     <div class="four columns">Baptist to Forest <br>Miles: 49.13</div>
  48.     <div class="four columns">Wait Time: 0:25:00 <br>Extra Pax/Stop: 0/0</div>
  49.   </div>

  50. </div>
Here is the jquery code I'm struggling with.

  1. $('.dayhead').on('click', this, function() {
  2.       var rowsCollapse = $(this).nextUntil('.dayhead');
  3.       $(rowsCollapse).slideToggle();
  4. });
  5. $('.daytrip').on('click', this, function() {
  6.       var rowsCollapse = $(this).nextUntil('.daytrip');
  7.       $(rowsCollapse).slideToggle();
  8. });
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.