Answers for "Cannot read property 'classList' of undefined"

2

Cannot read property 'classList' of undefined

It means that document.getElementById("lastName") is returning undefined and you're trying to call classList on undefined itself.

In your HTML input has the attribute name which equals lastName but there is no actual id="lastname"

Either add the attribute id to your input or change getElementById to getElementsByName.

Note that getElementsByName doesn't return a single item.
Posted by: Guest on July-20-2020

Code answers related to "Cannot read property 'classList' of undefined"

Code answers related to "Javascript"

Browse Popular Code Answers by Language