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 One Solution

Use querySelector / querySelectorAll only

I've used almost all for " querySelector / querySelectorAll " only and it works.

Would this be a good practice or should I be strictly using Sibling / Child in future for projects?

1 Answer

Bella Bradbury
.a{fill-rule:evenodd;}techdegree seal-36
Bella Bradbury
Front End Web Development Techdegree Graduate 32,790 Points

Honestly it depends on the situation. Using querySelector and querySelectorAll are wonderful when you have easily identifiable elements (i.e. with a class, id, or specific tag name) to import. Being able to traverse the DOM is important for when you don't have an easy identifier for an element(s) that you want to interact with. Another good example of when to use traversal over identification could be when you want to interact with an element in a specific position without having to add a class or id that specifies when the element is in that position.

Hope this helps!