The selector you have is almost correct.
a#followed_by+h4.li_group ~ div.soda a
The ~
works differently to the +
in that it will select any matching element after the first part of the selector, whereas the +
will only select elements immediately following the first part of the selector.
Of course, by "first part" I am referring to a#followed_by+h4.li_group
.
I've also changed the selector to find div.soda
rather than div.odd
so you get all relevant elements, rather than just the odd ones.
Because of the way CSS selectors work, we can't ask for "only elements up until edited_into
". We can, however resolve this using JavaScript.
A simple for
loop with a conditional break
will be the simplest method.
var titles = [];
var items = document.querySelectorAll('a#followed_by+h4.li_group ~ div.soda a');
//firstEditedIntoItem represents the first element in
//the `edited_into` section. If it's null, then there
//is none, and we have nothing to worry about.
var firstEditedIntoItem =
document.querySelector
('a#edited_into+h4.li_group+div.soda a, a#spin_off_from+h4.li_group+div.soda a');
// Note: This selector will find the first instance that matches any of the
// specified sections. You could add another and replace `spin_off_from` with
// another section id.
for(var i=0; i<items.length; i++) {
var it = items[i];
//don't accept elements after 'edited_into'
// If firstEditedIntoItem is null, it will not match either.
if(it==firstEditedIntoItem) break;
titles.push(it.textContent);
}
console.info(titles.join('\n'));