Input value returns Null

Input value returns Null


Trying to create something a button that can get the value in an element but i keep getting the error " Cannot read property ‘value’ of null"

I did some research and found out it’s because javascript loads before the HTML elements but from my logic, doesn’t my code only get the value of userInput after i click the search button?

This is my code:


The issue is in the following line:

var userInput = (document.getElementById('#userInput')).value();

When using getElementById, do not include the # in front of the id name.

Also, value is not a function (it is a property), so you do not need the () at the end.