Select elements with an attribute with cheerio

charly rl picture charly rl · Dec 17, 2016 · Viewed 19.8k times · Source

What is the most efficient way to select all dom elements that have a certain attribute.

<input name="mode">

With plain javascript I would use : document.querySelectorAll("[name='mode']") or document.querySelectorAll("[name]") if I don't care about the attribute value.

Answer

charly rl picture charly rl · Dec 17, 2016

Ok I found it in the cheerio documentation, here is how you do it:

$('[name=mode]')

cheerio docs: Selectors