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 CSS Selectors Quickstart The Role of Selectors in JavaScript Selectors in JavaScript Review

Chuwen Tan
Chuwen Tan
5,787 Points

About Quiz of Attribute Selector

The question is:

Consider the following HTML code:

<button type="button" class="close" data-close="modal">

Use an attribute selector to assign an element with a data attribute of data-close to the variable closeBtn:

var closeBtn = document.querySelector('???');

I filled in button[data-close="modal"] in the ??? place. I was wondering what the problem was. It did not pass the test. Thank you.

2 Answers

Steven Parker
Steven Parker
231,269 Points

It certainly looks like it should work. But even though the sample shows the attribute as having the value "modal", the instructions only say to select "an element with a data attribute of data-close"

So select using the existence of the attribute only, without restricting it to specific contents.

Chuwen Tan
Chuwen Tan
5,787 Points

Thank you Steven. May I seek your assistance to elaborate more?

The original question: var closeBtn = document.querySelector('???');

I tried to type in [data-close="modal"], but it showed incorrect. Then, I typed in data-close, but it also showed incorrect.

Steven Parker
Steven Parker
231,269 Points

You still need the brackets around it to make it an attribute selector.

Chuwen Tan
Chuwen Tan
5,787 Points

Thank you Steven. I typed in button[data-close]. And it showed correct. Thank you so much for your assistance!