JavaScript AJAX Basics (retiring) AJAX and APIs Stage 4 Challenge Answer

Qasim Hafeez
Qasim Hafeez
12,730 Points

Why does it have to be .val()?

Before I watched Dave's hints in the previous video, I tried to use .text() instead of .val() and it didn't work. The images that were returned had nothing to do with the search term. When I changed it to .val(), it worked fine. Why?

3 Answers

Ryan Zimmerman
Ryan Zimmerman
3,854 Points

.text() looks for a specific thing called the innerText where as .val() actually works on the input element.

Kaj Clausen
Kaj Clausen
15,192 Points

In others words, the .val() method looks for the value the person typed into the given input.

Hanxiao Jiang
Hanxiao Jiang
8,526 Points

I didn't use .val(), just searchTemp. But it still works