Delete all (brother) elements AFTER a certain element?

Delete all (brother) elements AFTER a certain element?

Assume I specify a certain element (e.g. with class="foobar").
This element and all following brother elements should be deleted but NOT the brother elements BEFORE

Example

  1. <div class="....">
  2.    <div class="aaa">...</div>
  3.    ...
  4.    <div class="foobar"> .... </div>
  5.    <div class="bbb> ... </div>
  6.    ....
  7.    <div class="bbb> ... </div>
  8. </div>
  9. <div class="parentbrother>...</div>

How can I achieve this (keep in mind that no brother elements could follow)?

The following (Javascript) code deletes ALL elements (which is not intended":

  var elem = $(".foobar")[0];
 
  if (elem) {
     var pelem=elem.parentNode;
     while (pelem.lastChild!=elem) {
       pelem.removeChild(pelem.lastChild); // remove succeeding siblings
       }
     pelem.removeChild(pelem.lastChild); // remove itself
     }

Additional, related question:

Assume not only the following brother elements should be deleted but also all following elements on a higher level (here with class="parentbrother").

How can I achieve this?

Possibly there is an easier way with jQuery

Thank you
Peter