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 Treehouse Club - MASH MASH - JavaScript Fill in Answers and Get Answers Functions

Mahmoud Amin
PLUS
Mahmoud Amin
Courses Plus Student 6,269 Points

A syntax

I don't understand this syntax at all var selector = 'input[name="' + category + '[]"]'; and what does the (input) keyword generally mean

1 Answer

Steven Parker
Steven Parker
231,269 Points

This code is building a CSS selector, and input is the HTML element type that the selector will be looking for. The inputs in this case are text boxes on the form.

For example, if you were to make this call: get_answer("pet"), then after your statement above, the variable selector would contain this string: input[name="pet[]"].

If you look in the index.htm file, you will see that there are several input elements that have the name "pet[]" (on lines 43-46). These are the elements that the selector will find.

Make sense now?

Kegan Windle
Kegan Windle
2,217 Points

What does a CSS selector do? Is it styling the answers? I thought CSS was just for adding style to the HTML structure.