How to group only VISIBLE posts? [closed]

Give the divider an attribute, ie: data-target=".group_20211006" and add class to the post container, ie: class="blah group_20211006". After the filter changes, loop through each divider and check if there’s any visible post container with matching date value.

HTML

<!-- First Group -->
<div class="divider" data-target=".group_20211001">October 1, 2021</div>
<div class="post-1 group_20211001">...</div>
<div class="post-2 group_20211001">...</div>
<div class="post-3 group_20211001">...</div>

<!-- Second Group -->
<div class="divider" data-group=".group_20211006">October 6, 2021</div>
<div class="post-1 group_20211006">...</div>
<div class="post-2 group_20211006">...</div>
<div class="post-3 group_20211006">...</div>

jQuery

(function($){
  $(document).ready(function(){
    $(document.body).on('change', '.myfilter', function(){
      $('div.divider').each(function(e, el){
        if ( $($(el).attr('data-group')).is(':visible').length > 0 ) {
          $(el).show();
        } else {
          $(el).hide();
        }
      });
    });
  });
})(jQuery)

I haven’t tested, but this should be the concept to make it work.