Skip to content

Docs don't explain why sub-selected instances of cheerio don't have text(), html() or find() functions defined. #4494

@sanfordstaab

Description

@sanfordstaab

[email protected]

Example code:

//test.js
'use strict';

import * as cheerio from 'cheerio'

const $root = cheerio.load(`
  <div class="foo">
    This is my text
  </div>
  <div class="foo">
     <div class="bar">
       this is more text
    </div>
  </div>`);

console.log($root.text());
console.log($root.html());

const $sub = $root('.foo');
console.log($sub.text());
console.log($sub.html());
console.log($root.find('.bar')); //$root.find is not a function

$root('.foo').each(
  (i, $foo) => {
    console.log(`${i} ${$foo.html()}`); // $foo.html is not a function
    console.log(`${i} ${$foo.text()}`); // $foo.text is not a function
  }
)

The docs at do not show any examples of using select result instances of cheerio. Nor do they articulate how this object differs from the root.
They say find() is available, but it doesn't work for me.
The function .each(), though it works, is nowhere in the docs that I could find either.
I am so confused!

Contact me a [email protected] if needed.

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