What appears to be the obvious option in jquery: .next("dt")
is not, because .next()
always only returns the very next sibling, applying a filter .next(filter)
still only returns the very next sibling, but only if it matches the filter
jQuery provides two alternatives: .nextUntil() and .nextAll()
These can be used as:
nextdt = thisdt.nextUntil("dt").next();
nextdt = thisdt.nextAll("dt").first();
where nextUntil gets the next siblings until the match (so you then need another next()) and nextAll gets all the matching (so you then need first()).
In the question's code, this gives the following update:
jQuery('.accordion > dt').on('click', function() {
$this = $(this);
$target = $this.nextAll("dt").first();
Example fiddle: https://jsfiddle.net/0wk1mkeq/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…