So I just started with Cheerio the other day. I have a situation where I have several divs to iterate over and based on its childrens' contents I have to do different things.
The basic HTML structure:
<div class="a">
...
<div class="b">Hi</div>
...
</div>
<div class="a">
...
Here is the javascript:
$('.a').each(function(){
if($('.b', ??).eq(0).html() == "Hi") ...
else($('.b', ??).eq(0).html() == "Bye") ...
The question is what to put in the ??. I can't just put ".b" cause that won't give me the contents specific for that div. Optimally I would like to pass "this" or "$(this)". But neither of them are DOM elements.
I was just wondering what the most clean solution to this problem is. I could try grabbing the n-th children of the div. But what if ".b" isn't guaranteed to be the n-th child? I also thought about getting the HTML from $(this) then creating a new DOM but that seems like another inefficient hack.
Thanks