I’m trying to count the amount of yes’s up to a specific span specified by :contains(certain sring). I basically just want to search the first half of this group of questions for how many yes’s there are. Here’s the code I have tried:
<div class="ce-modal-container">
<div class="ce-cf-container">
<span class="ce-cf-html-label">Have you chosen your exit path and/or successor?:</span>
<span class="ce-cf-html-field"> Yes</span>
</div>
<div class="ce-cf-container">
<span class="ce-cf-html-label">Have you chosen your exit path and/or successor?:</span>
<span class="ce-cf-html-field"> No</span>
</div>
<div class="ce-cf-container">
<span class="ce-cf-html-label">Have you done well this quarter?:</span>
<span class="ce-cf-html-field"> No</span>
</div>
<div class="ce-cf-container">
<span class="ce-cf-html-label">Have you chosen your exit path and/or successor?:</span>
<span class="ce-cf-html-field"> Yes</span>
</div>
<div class="ce-cf-container">
<span class="ce-cf-html-label">Have you chosen your exit path and/or successor?:</span>
<span class="ce-cf-html-field"> Yes</span>
</div>
</div>
<script>
var spanYes = $("span.ce-cf-html-field:contains('Yes')"),
secondHalf = $("span.ce-cf-html-label:contains('done well')"),
searchtxtall = spanYes.length;
searchFirstHalf = $(".ce-cf-container").nextUntil(secondHalf).spanYes.length;
console.log(searchtxtall); //should return 3
console.log(searchFirstHalf); //should return 1
</script>
Thanks in advance I know it’s a lot of code.
Another solution that’s a little less fancy: