Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.