1

I wrote some code that is scanning my HTML table, and I want to use it for formatting that table.

var count_rows = document.getElementById("currency_tab").rows.length;
for (i = 0; i <= count_rows; i++ ) {
  var count_cells = document.getElementById("currency_tab").rows[i].cells.length;
  for (j = 0; j <= count_cells; j++) {
    var check_str = document.getElementById("currency_tab").rows[i].cells[j];
    /*  
    console.log(check_str);
    console.log(typeof(check_str));
    */
    var check = check_str.includes("-")
    if(check) {
      check_str.style.color = "red";
    } else {
      check_str.style.color = "green";
    }                              
  }
}

js console.log(check_str); is returning not a value of cell but an object e.g. <th>CURRENCY</th>. I have tried to parse it with check_str.slice but that is forcing me to count a length of chars in object. I hope there is easier method to resolve that.

Mark
  • 9,718
  • 6
  • 29
  • 47
Sjevi
  • 39
  • 5
  • [`check_str.textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent) – Phil Apr 01 '20 at 23:18

1 Answers1

4

You can get the text with check_str.textContent

Please refer to the following documentation: Node.textContent

Also, if you are unsure about the properties of an object you can log them with console.dir(check_str).

Luís Ramalho
  • 10,018
  • 4
  • 52
  • 67