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?

2 Answers

Mikkel Rasmussen
Mikkel Rasmussen
31,768 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.