I have some rather annyoing piece of HTML given and want to iterate over all list elements under the given headline. Unfortunately, there are some comments in between that I'd like to skip.
<header><h2>A</h2></header>
<ul class="list">...</ul>
<header><h2>C</h2></header>
<p>Some comment</p>
<ul class="list">...</ul>
<p>Another comment</p>
<ul class="list">...</ul>
<header><h2>B</h2></header>
<p>Some comment</p>
<ul class="list">...</ul>
I've tried document.querySelectorAll('h2 ~ .list:not(h2)')
, but this returns nothing.
So, ideally, I'd go over each header and for each header retrieve the list
s, something along the lines of
const headers = document.querySelectorAll('h2');
for(let i = 0; i < headers.length; ++i)
{
// Somehow get an Array of `list` elements between h2 i and i+1
}