Using I Cheerio I want to select the text of theses parts:
this is the first area to select
this is the second area to select
<div class="lun boxBd boxMain" t="page">
<div id="boxWrd" class="boxLtr">
<div>
<h1>trust</h1><i class="aud"><span class="ico icoAu"></span></i>
</div>
<div>
<div id="pho">/ˈtrəst/<i class="aud" onclick="tts("trust", "us")"><span class="ico icoAuUs"></span></i><i id="phSep"></i>/trʌst/<i class="aud" onclick="tts("trust", "uk")"><span class="ico icoAuUk"></span></i></div>
</div>
</div>
<hr>
<b>meaning</b>:
this is the first area to select
<hr>
<b>other meanings</b>:
this is the second area to select
<div id="meanTools"><i class="ico icoSt" onclick="starWm()"></i><i class="ico icoCo" onclick="copyWm()"></i>
<cgr id="msgTools"></cgr>
</div>
</div>
Selecting the b tags is easey:
$('.boxMain b').toArray().map(item => $(item).text());
But How can we select under them and get the desired text?
2
Answers
.nextSibling
This is a bit complicated, especially compared to the other answer here, but it works. The explanation is in the comments
Greatly simplified version thanks to the above answer from Ronnie Royston. This is probably a much better way to go!