The below script generated a table whose cell color can be updated by clicking on it. I was trying to update the code in a way that on a single click and drag (multi select) it should be able to update the colors of multiple cells and I am out of ideas for it.
const table = document.getElementById("table");
table.innerHTML = "";
// size has a value for number of column and rows
for (let i = 0; i < this.size; i++) {
let tr = document.createElement("tr");
for (let j = 0; j < this.size; j++) {
let td = document.createElement("td");
td.classList.add("border-clr");
// backRBG is a variable that stores my color and backRBG2 is a variable that stores my clicked color
td.style.backgroundColor = backRGB;
td.onclick= () => {
td.style.background= backRBG2
}
tr.appendChild(td);
}
table.appendChild(tr);
}
Thank you in advance.