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
- <div class="....">
- <div class="aaa">...</div>
- ...
- <div class="foobar"> .... </div>
- <div class="bbb> ... </div>
- ....
- <div class="bbb> ... </div>
- </div>
- <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