Skip to content

:scope selector not working on root node #4509

@ShadyShenAli

Description

@ShadyShenAli

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions