Im new to coding and Im trying to make a "page not found" page but im getting the following error
Uncaught TypeError: Cannot read properties of undefined (reading 'add')
How can I solve this problem?
Here is the code:
setTimeout(function () {
const notFoundElement = document.getElementsByClassName(
"not-found-animation"
);
notFoundElement.classNameList.add("hinge-falling");
console.log("setTimeout Loaded...");
}, 2200);
<h1 className="not-found-animation">404</h1>
4
Answers
you need to access the first element in the collection using [0],
Try:
did you by any chance mean classList.add? although i cant rly see how is that react related
try this notFoundElement.setAttribute(‘class’,’hinge-falling’)
Don’t use the original DOM in React (bad practice).
solutions