remove empty spaces around cells in HTML table

I am trying to crrate a chessboard using HTML and JS. I’m using HTML tables for that purpose. but I’m not sure why but there is are empty spaces around each cells.
I’ve tried cell-spacing:0; but it doesn’t seems to work.

see the red background around cells. Here is the code

var table = document.createElement("table");
table.id = "board";
table.classList.add = "div2";
for (var i = 1; i < 9; i++) {
  var tr = document.createElement('tr');
  for (var j = 1; j < 9; j++) {
    var td = document.createElement('td');
    if (i % 2 == j % 2) {
      td.className = "white";
    } else {
      td.className = "black";
    }
    tr.appendChild(td);
    td.innerHTML += td.cellIndex + 1;
  }
  table.appendChild(tr);
}
document.body.appendChild(table);
* {
  margin: 0;
  padding: 0;
}

body {
  background: red;
  display: flex;
  width: 100vw;
  height: 100vh;
  align-items: center;
  justify-content: center;
  overflow: scroll;
}

.black {
  background: #769656;
}

.white {
  background: #eeeed2;
}

table {
  border: 2px solid red;
  width: 95vw;
  cell-spacing: 0;
  cell-padding: 0;
  height: 95vw;
}

.div2 {
  width: 95vw;
  height: 95vw;
}

I’m prefering javascript or css solutions to this. Thanks.

Answer

Set table.cellSpacing = 0; before adding the table to the document :

var table = document.createElement("table");
table.id = "board";

table.cellSpacing = 0;

table.classList.add = "div2";
for (var i = 1; i < 9; i++) {
  var tr = document.createElement('tr');
  for (var j = 1; j < 9; j++) {
    var td = document.createElement('td');
    if (i % 2 == j % 2) {
      td.className = "white";
    } else {
      td.className = "black";
    }
    tr.appendChild(td);
    td.innerHTML += td.cellIndex + 1;
  }
  table.appendChild(tr);
}
document.body.appendChild(table);
* {
  margin: 0;
  padding: 0;
}

body {
  background: red;
  display: flex;
  width: 100vw;
  height: 100vh;
  align-items: center;
  justify-content: center;
  overflow: scroll;
}

.black {
  background: #769656;
}

.white {
  background: #eeeed2;
}

table {
  border: 2px solid red;
  width: 95vw;
  cell-spacing: 0;
  cell-padding: 0;
  height: 95vw;
}

.div2 {
  width: 95vw;
  height: 95vw;
}