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

:nth-child() selector returns empty result #143

Closed
piffie opened this issue Dec 30, 2012 · 8 comments
Closed

:nth-child() selector returns empty result #143

piffie opened this issue Dec 30, 2012 · 8 comments

Comments

@piffie
Copy link

piffie commented Dec 30, 2012

i know that :eq() is not implemented,
but nth-child is. (https://github.com/fb55/CSSselect/blob/master/index.js#L179)

anyways, always returns an empty result set.

@piffie piffie closed this as completed Dec 30, 2012
@matthewmueller
Copy link
Member

did you resolve the issue?

@piffie
Copy link
Author

piffie commented Jan 2, 2013

Yep. it was on my side. sorry for that.
the selector works perfectly

@Hamdan85
Copy link

Hamdan85 commented May 5, 2014

piffie, how did you solve that?

@Hamdan85
Copy link

Hamdan85 commented May 5, 2014

Just solved it myself:

the correct is $('.classSelector div:nth-child(n)') and not $('.classSelector:nth-child(n)')

@tp
Copy link
Contributor

tp commented May 5, 2014

@Hamdan85 I don't think that is corrent.

https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child

Gives an example of element:nth-child(an + b) { style properties }.

Note that it is using : before nth-child and not . as you suggest.

Did you mix this up, or is it a bug in cheerio?

@Hamdan85
Copy link

Hamdan85 commented May 5, 2014

oh.. im sorry... that was a misstyping. you are absolutely correct.!]

But this particular part was not the point. I just corrected the solution.

@coderofsalvation
Copy link

I had a similar problem:

div.result_data > table > tbody > tr:nth-child(1) > td:nth-child(2)

did not work (although it matches the html markup)
This however did work:

div.result_data > table > tr:nth-child(1) > td:nth-child(2)

My theory: chrome's fault.
I rightclicked the element inside the chrome inspector and pressed 'copy css path'.
Chrome generates the CSSPath from the generated DOM (which autocorrects missing elements like <tbody> in the DOM.).

So my advice, make sure all elements are present in the actual html :)

@kunKun-tx
Copy link

Firefox also seems to like insert a tbody.
More for this question on SO

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

6 participants