HTMLElement.querySelector() using cheerio

Viewed 267

Using vanilla JavaScript, you can write

const box = document.querySelector(".box");
const button = box.querySelector(".button");

How about Cheerio? I want to do something like:

const box = $(".box");
const button = box.$(".button")

I'm asking because I have to loop over elements then find an anchor tag within that element:

const $ = cheerio.load(stdout)
      const boxes = $(".box").map((i, element) => element)
      boxes.each((i, element) => ?? maybe element.querySelector("a") )
1 Answers

If you don't want to use descendant combinator you can use find:

const button = box.find("button");
Related