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

Examples using .html() show inaccurate return values #4165

Open
nex3 opened this issue Oct 22, 2024 · 1 comment
Open

Examples using .html() show inaccurate return values #4165

nex3 opened this issue Oct 22, 2024 · 1 comment

Comments

@nex3
Copy link

nex3 commented Oct 22, 2024

According to the documentation for Cheerio<T>.html(), it returns the content of the element—that is, its innerHTML rather than its outerHTML. This matches the current behavior. However, many documentation examples are written as though it returns the outerHTML. For example, this is the code snippet from Cheerio<T>.addClass():

$('.pear').addClass('fruit').html();
//=> <li class="pear fruit">Pear</li>

$('.apple').addClass('fruit red').html();
//=> <li class="apple fruit red">Apple</li>

We can test this in the browser's dev inspector:

const cheerio = await import("https://jspm.dev/cheerio");
const $ = cheerio.load('<ul><li class="pear">Pear</li><li class="apple">Apple</li></ul>');
console.log($('.pear').addClass('fruit').html());
console.log($('.apple').addClass('fruit red').html());

where it prints

Pear
Apple

rather than the documented output values.

@Lansa-18
Copy link

Hello, I am a Frontend Developer looking to increase my experience in open source. Can i work on this?

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

No branches or pull requests

5 participants
@nex3 @Lansa-18 and others