Search code examples
javascriptnulltypeerrorinnerhtml

Given error Uncaught TypeError: Cannot set property 'innerHTML' of null when button is clicked


I have an error being displayed in my code.

With this button:

 <button style="display:none" id="saveH" class="btn btn-primary" onclick="makeToDoList(); displayTDL();">Save</button> 

When the button is clicked it suppose to display a div that lists what the user inputs in the "form". However, when I run the code it gives me this error: 1025:59 Uncaught TypeError: Cannot set property 'innerHTML' of null

Here is a link to a JSFiddle with my code


Solution

  • The error

    Uncaught TypeError: Cannot set property 'innerHTML' of null

    suggests that it can't set the innerHTML property of an a null value. A null value is the result of a getElementById() query which comes up empty.

    So looking at what line the error occurs you can see it can't set the innerHTML of the result9h element. And that is because it does not exist in your HTML.