0

I'm not sure what I'm doing wrong. It's probably very obvious. Works on codepen, but when testing on my site, I receive the error: 'TypeError: row is undefined'

HTML:

<table class="tabletable">
<tr class="fee">
  <th>Name</th>
  <td>--</td>
  </tr>
 </tfoot>
</table>

Javascript:

function feefee(){
 var row = document.getElementsByClassName("fee")[0];
  for (i=0; i<1; i++) {
   var x = row.insertCell(2);
   x.innerHTML = "New cell";
 }
}
function feefee();

Here is a codepen where it works fine, unfortunately it doesn't work on-site: http://codepen.io/xkurohatox/pen/XdZEyQ?editors=1010

I am attempting to add a new cell after div class .fee td.

No jQuery answers please. Thank you!

xkurohatox
  • 198
  • 1
  • 16
  • @Oriol Can you link me to the duplicate of this question? I never asked this before, and see no other questions like this. Row:undefined, yes, but not with this script. – xkurohatox Apr 11 '16 at 22:12
  • 1
    The link should appear at the top: [Why does jQuery or a DOM method such as getElementById not find the element?](http://stackoverflow.com/q/14028959/1529630). Most probably you call that function before the element has been loaded. You should call it later. – Oriol Apr 11 '16 at 22:13
  • Thanks @Oriol. By the link, are you saying this is a load error? Edit: Just saw your edited comment. I will take your advice. Thank you again. :) – xkurohatox Apr 11 '16 at 22:16
  • 1
    By the way, make sure to initialize `i` with `var i` ; otherwise `i` will become a global variable which can have unexpected consequences – gengkev Apr 11 '16 at 22:19

0 Answers0