Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

How to change background color of a table cell in java script using row and column number?

$
0
0

I am trying to change the background color of a cell depending on my row and col id. I have tried like this but didn't work.

let rowNumber = 1;
let colNumber = 1;
document.getElementById("myTable").rows[rowNumber].cells.item(colNumber).style.backgroundColor = "red";
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><table id="myTable"><tbody><tr><td>0-0</td><td>0-1</td><td>0-2</td></tr><tr><td>1-0</td><td>1-1</td><td>1-2</td></tr><tr><td>2-0</td><td>2-1</td><td>2-2</td></tr></tbody></table>

Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>