Skip to content
Advertisement

getElementById not working on td elements

I am trying to access table elements with getElementById but this code is giving me “null” as the console log? Does getElementById not work with tables?

JavaScript

Advertisement

Answer

Your HTML is invalid. While I can reproduce your problem by copy/pasting your code “as is”, it works fine if you put the <tr> and <script> elements in places they are allowed (i.e. as a child of a <table> and not as a sibling of <tr> respectively).

Use a validator to identify errors in your HTML.

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