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

Can't get button value using the val function #3951

Open
ribeirobreno opened this issue Jul 30, 2024 · 5 comments · May be fixed by #4175
Open

Can't get button value using the val function #3951

ribeirobreno opened this issue Jul 30, 2024 · 5 comments · May be fixed by #4175

Comments

@ribeirobreno
Copy link

In the latest version (0.22.0), getting a button value is not possible with the .val() function.

import * as cheerio from "cheerio";

let ch = cheerio.load(`<form><button value="something">I'm a button</button></form>`);
console.log(ch('button').val());
console.log(ch('button').attr('value'));

The code snippet above will return:

undefined
something

To match jQuery behavior, it should return:

something
something
@ribeirobreno
Copy link
Author

ribeirobreno commented Jul 30, 2024

Adding more context, jQuery documentation is a little misleading in stating that "val" will try to get the value from a specific list of tags. In fact, it will get the "value" attribute from anything that has this attribute in their DOM prototype.
See:

@fb55
Copy link
Member

fb55 commented Aug 9, 2024

Thanks for the links! Happy to accept PRs for this.

@PRASUN-SITAULA
Copy link

Hey @fb55 can I work on the issue?

@fb55
Copy link
Member

fb55 commented Oct 1, 2024

For sure! PRs welcome

@PRASUN-SITAULA
Copy link

Thanks @fb55
Could you please let me know which part of the source code I should change for?
Thanks!

@kaioduarte kaioduarte linked a pull request Oct 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants