Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A selector relative to the parent selector does not work (different behaviour from jQuery) #1244

Closed
gajus opened this issue Oct 31, 2018 · 6 comments · Fixed by #1583
Closed

Comments

@gajus
Copy link

gajus commented Oct 31, 2018

const subject = `
<div>
  <p class='a'>FOO</p>
  <p class='b'>BAR</p>
</div>
`;

const $ = cheerio
  .load(subject, {
    xmlMode: false
  })
  .root();

console.log($.find('.a').find('+.b').length);

Actual result: 0
Expected result: 1

If you try the same in jQuery, you will get the expected result. https://codepen.io/anon/pen/WaqdEN

Scoped search with a predefined context does not work either:

const subject = `
<div>
  <p class='a'>FOO</p>
  <p class='b'>BAR</p>
</div>
`;

const $ = cheerio
  .load(subject, {
    xmlMode: false
  })
  .root();

console.log($.find('+.b', $.find('.a')).length);

Actual result: 0
Expected result: 1

Again, it works in jQuery. https://codepen.io/anon/pen/oarpod

@gajus
Copy link
Author

gajus commented Oct 31, 2018

@jugglinmike am I overlooking something obvious?

@gajus
Copy link
Author

gajus commented Oct 31, 2018

Tested https://github.com/cheeriojs/cheerio/tree/v1.0.0 branch with the latest fb55/css-select#42 changes. Same issue persists.

@fb55
Copy link
Member

fb55 commented Oct 31, 2018

Has not been fixed yet, generally a pretty gnarly issue. Happy to accept PRs for this!

@gajus
Copy link
Author

gajus commented Oct 31, 2018

Has not been fixed yet, generally a pretty gnarly issue. Happy to accept PRs for this!

Is there a workaround that you propose at the moment?

Some meta selector such as :scope or whatever.

@fb55
Copy link
Member

fb55 commented Nov 2, 2018

:scope is implied when the selector starts with >. This very much seems like a bug when passing contexts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants