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 trial

JavaScript

ryan champin
ryan champin
16,836 Points

jquery selector questions

if we can access an crazy nested element of the page with css like

ex: .class anotherClass:nth-child(3n+3) why cant we do that when we select a dom element with $('.class anotherClass:nth-child(3n+3)');

unless im just crazy and this hasnt been working and ive been forced to use the jquery selectors like .children .siblings etc. and also i guess can someone explain to me the official can-do's and cant do's of element selection with jquery?

2 Answers

Hi Ryan,

I think this codepen demo is doing what you think you can't do: http://codepen.io/anon/pen/ajgEF

Do you have a specific example of what's not working for you?

ryan champin
ryan champin
16,836 Points

ok so basically i just happen to be messing up the selectors when im in jquery...thats weird...lol so basically there is no need to the traversal methods in jquery for basic selections.....thank u so much

It depends on what you're trying to do but .children() and .siblings() still have their uses.

Some methods only act on the 1st element in a set of matched elements. Is it possible that you used one of those methods and it led you to believe your selector wasn't selecting multiple items?

Also, to answer your final question, I believe any valid css selector can be used to select elements with jQuery.