Probably better in javascript, but this can sure include jQuery, or any such library.
I want to find the first .next
in the example below.
There are a lot of answers to similar questions that suggest nextAll
or siblings
... Both are useless here:
$(function(){
$('.result').text(
$('.origin').nextAll('.next').text()
|| $('.origin').siblings('.next').text()
|| 'both failed'
)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="whatever">
<p class="result"></p>
<p class="origin">1</p>
</div>
<p class="next">2</p>
<p class="next">3</p>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…