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

closest() should be able to start from text nodes #2810

Closed
Qualtagh opened this issue Oct 20, 2022 · 0 comments · Fixed by #2811
Closed

closest() should be able to start from text nodes #2810

Qualtagh opened this issue Oct 20, 2022 · 0 comments · Fixed by #2811

Comments

@Qualtagh
Copy link
Contributor

A function closest() is now working only on tags. It used to work on text nodes too on 1.0.0-rc.10.

Breaking commit: #2057

parent(), parents() and parentsUntil() functions still work for text nodes though. I expect closest() to behave the same way.

Example:

const cheerio = require('cheerio');
const $ = cheerio.load('<span>abc</span>');
const textNode = $('span').contents().first();
console.log(textNode.closest('span').length);

Expected output is 1 (i.e. closest span has been found), current version returns 0.

I'll create a pull request soon.

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.

1 participant