Home > Mobile >  Can I select again from element variable in Cheerio?
Can I select again from element variable in Cheerio?

Time:02-21

I just started using Cheerio. How can I select again from a loop element?

const championBox = $('div.css-1s4j24f>div');
championBox.each(async function(index, element) {
    console.log(
    // I want to get element>div.something>span.somethingelse
    )
})

Thanks in advance.

CodePudding user response:

You can use .find, it is the cheerio equivalent of .querySelectorAll.
Using > at the start of the string makes it behave like element > div.something ...

const championBox = $('div.css-1s4j24f>div');
championBox.each(async function(index, element) {
    console.log(
        $(element).find('>div.something>span.somethingelse')
    )
})

CodePudding user response:

const championBox = $('div.css-1s4j24f>div');
championBox.each(async function(index, element) {
    const result = $(element).find('div.something>span.somethingelse');
})
  • Related