Skip to content

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

@Qualtagh

Description

@Qualtagh

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.

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