Skip to content
Advertisement

Can not get the element [closed]

Hello so when I try to get the tbody element in JavaScript I get the error that it is null But whenever I use the same method to get the element but in a different file it works perfectly.

I have tried getting the element by id and class but nothing seems to be working.

Here is my HTML:

JavaScript

And my JS

JavaScript

(UPDATE the problem was solved by adding the script to the bottom of the file)

Advertisement

Answer

this is how u can get ur tbody element

JavaScript

so instead of

JavaScript

use :

JavaScript

by the way u can replace

JavaScript

with

JavaScript

to make your code more readable

and dont add an event listener as attribute as u did here

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement