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 AJAX Basics (retiring) AJAX and APIs Stage 4 Challenge Answer

Not 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?

https://w.trhou.se/or41dhimed

2 Answers

Mikkel Rasmussen
Mikkel Rasmussen
31,772 Points

Its should work maybe its because you are missing a semi colon?

var animal = $('#search').val();

You 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.