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 trialSunny Singh
1,148 PointsNot understanding .Alternate way to display search term photo not working
why does Instead of defining
var $searchField = $('#search');
and then
var animal = $searchField.val();
you can't simply do
var animal = $('#search').val()
It does not work?
2 Answers
Mikkel Rasmussen
31,772 PointsIts should work maybe its because you are missing a semi colon?
var animal = $('#search').val();
Iain Simmons
Treehouse Moderator 32,305 PointsYou would use the two separate variables if you needed to access the actual element as a jQuery object for something else (like changing the value later, adding/changing classes, etc).
But otherwise, yes, your code is a little shorter.