Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSaqib Ishfaq
13,912 Pointsany reason why these wont work? ('li:nth-child(even)') this wont work if there is space b/w semi colon and nth-child
secondly can we not use querySelectorAll on getElementsByTagName('li') ??
3 Answers
Steven Parker
231,269 PointsBen's right about not using a space there. And you certainly can use querySelectorAll on getElementsByTagName('li'), but that might not be the solution you need.
For a more complete answer, please show the whole code, and provide a link to the course page so we can see what you're working on.
Saqib Ishfaq
13,912 Pointshi this is the code i was referring to!! https://w.trhou.se/vu1g2aeec5
it doesnt work when i use querSelectorAll('li') plus i thought space is invalid ...between semi colon and nth-child
Steven Parker
231,269 PointsYes, space is invalid there. But it's a colon : (this is a semicolon ; ).
And the code in your snapshot seems to be working. Every other line has a grey background. Can you describe what's happening (or not happening) that seems wrong?
Saqib Ishfaq
13,912 Pointsah sorry yeh i meant colon:
ok this code is the one where theres space b/w colon and nth child and it doesnt work for even lists coloured as grey, but when i omit space it works fine! its not big issue i can remember to not leave space b/w them but wondering is it the general practice or is there something wrong with it? coz i taught myself that space doesnt matter in JS.
where as the other issue worked just fine i tried replacing "getElementsByTagName('li')" with querySelector('li') and it worked ,after i sent u this link for the workspace.
https://w.trhou.se/s2gj44q4wd
Steven Parker
231,269 PointsThis is CSS, not JS. And spaces do matter, sometimes. One place they matter for sure is in selectors. A space creates a "descendant selector". And a colon must come directly in front of a pseudo-class, just like a period must come directly in front of a class.
Saqib Ishfaq
13,912 Pointsoh yeh that indeed is css and not js ....thanks steven for helping clear my mind !
Ben Payne
1,464 PointsBen Payne
1,464 PointsI think if you put a space after the
li
selector you're selecting the nth-child of descendants.