How do I get an element's name in cheerio?
The jQuery equivalent would be .attr('name')
but that returns undefined
in cheerio.
How do I get an element's name in cheerio?
The jQuery equivalent would be .attr('name')
but that returns undefined
in cheerio.
There's only one case, I suppose, when
$someElement.attr('name')
returnsundefined
- if there's NO attributename
on that element. For example...Note that
<name>
attribute is only applicable to the following set of elements (MDN):To get the name of the element itself (it's tagName actually, but Cheerio abstracts it), use
name
property of the underlying element wrapped in Cheerio container, like this: