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 trialLeo Marco Corpuz
18,975 PointsQuestion about tags:animal and selecting form element
Why is 'animal' the tags value and not the value of the search input? Also, why is the form element selected for the submit method instead of the actual submit button?
2 Answers
Steven Parker
231,269 PointsThe variable "animal" does contain the value of the search input. This happens on this line:
var animal = $searchField.val();
Here, "$searchField" is a jQuery object that refers to the input box, and the ".val" method gets the search input entered by the user.
The advantage of using the form as the source of the submit event is that the event can be generated more ways than just by using the button. In fact, in the video the button is not used, and the event is generated when the "Enter" key is pressed during the text input.
Leo Marco Corpuz
18,975 PointsThanks!