cheerio
cheerio copied to clipboard
:scope selector not working on root node
To select the direct child of the root node, I'm using :scope pseudo class in the selector. For example,
const html=`
<collection>
<id value="a"/>
<relatedCollections>
<collection>
<id value="a1"/>
</collection>
</relatedCollections>
</collection>
<collection>
<id value="b"/>
<relatedCollections>
<collection>
<id value="b1"/>
</collection>
</relatedCollections>
</collection>
`
let $ = cheerio.load(html,{xmlMode:true},false);
to get the root collection id, I'm using
$(":scope> collection > id").map(function(){ return $(this).attr("value");}).get()
, which should return ["a","b"] however, it is currently returning empty result []
Is it a bug? Any solution? or any workaround?
Thanks and Best Regards, Shady
a workaround has been found,
$(":root:is(collection) > id").map(function(){ return $(this).attr("value");}).get()
Although the original issue still persists.