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

Targeting the nested div. Why can't you use document.QuerySelector?

// 5: Store the nested div in a variable named `banner`
const banner = list.previousElementSibling;
banner.className = 'banner';

I know we were supposed to use .previousElementSibling like above.

But why wouldn't this work?

const banner = document.querySelector('h1 div');

I also tried:

const banner = document.querySelectorAll('h1 div');

I thought this would target the first div under the first h1. Thank you!

1 Answer

Steven Parker
Steven Parker
231,248 Points

The selector "h1 div" would target a div that is inside an h1 element. But nothing on the document fits that description.

The div in question is the adjacent sibling of the h1 element, and a selector for that would be "h1 + div".

Thank you Steven! That makes total sense.