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 trialMahmoud Amin
Courses Plus Student 6,269 PointsA 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
231,275 PointsThis 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?
Mahmoud Amin
Courses Plus Student 6,269 PointsMahmoud Amin
Courses Plus Student 6,269 PointsYeah That make sense now.......Thx
Kegan Windle
2,217 PointsKegan Windle
2,217 PointsWhat does a CSS selector do? Is it styling the answers? I thought CSS was just for adding style to the HTML structure.