0

I started programming a bit with HTML/CSS/js and I have a table with several rows with 2 elements each I was wondering how it's possible to give certain td Elements a text through a JavaScript function without giving them all an unique id or something.

I am searching for something similar to

for(i = 0; i < 10; i++) {
  table.at[i] = i+3;
}

and I am missing the at[i] part for it.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • Use `document.querySelector()` with an [nth-child](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child) selector? – Phil Nov 24 '21 at 23:54

1 Answers1

-1

You could use the children attribute

If you want to access the nth row of a table, use table.children[n+1] (first child of table is the header, if you don't have a header remove the +1). If you want to get to row y and column x, table.children[y+1]. children [x].

jbritain
  • 94
  • 4