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 select elements based on their position in the document #3547

Open
WilliamBelini opened this issue Dec 15, 2023 · 2 comments
Open

Can´t select elements based on their position in the document #3547

WilliamBelini opened this issue Dec 15, 2023 · 2 comments

Comments

@WilliamBelini
Copy link

From https://cheerio.js.org/docs/basics/selecting

Have a command documentation that inform you can select elements based on their position, like

const $p = $('p:first');

but if I want select $p = $('div div.first button').attr('onclick') it returns null.

if I write just
$('div div button').attr('onclick'),

it returns the first value

Always I need do
$('div div button').each((index,value) =>
$(value).attr('onclick')

(yes, the comand 'each' return the div>div elements).

And discard the 2 first elements to get my value.

I think it be more simple like
$('div div[2] button').attr('onclick')

Selecting the div position with "[2]", like an array element position.

Exist some form that I can't need make the 'each' command to return the values from 3th div?

If I write like the div:second, Google App Script retuns "Error: unmatched pseudo-class :second"

Thanks
gift

@fb55
Copy link
Member

fb55 commented Dec 16, 2023

What version of Cheerio are you using? Note that positional selectors are only available in the latest RC release.

@WilliamBelini
Copy link
Author

WilliamBelini commented Dec 16, 2023 via email

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

No branches or pull requests

2 participants