I'm trying to get the DOM element id to change the background of a <td>. I'm printing a calendar with a map function from an array called from an outer function and adding an onclick function to each loop. But when I click the <td> I get the last id from that row.
In the alert function, I get the value of the last day from the row
Any suggestions?
Calendar Example This is my code:
cols = new Array(7).fill(0).map((zero, arrayCounter) => {
if ((i === 0 && arrayCounter < weekDay) || numberDays < counterDay + 1) {
return (
<td id={arrayCounter} key={arrayCounter}>
</td>
);
} else {
return (
counterDay++,
(
<td
id={this.state.month + counterDay}
key={this.state.month + counterDay}
onClick={() => this.handleDays(actualRow, counterDay)}
>
{counterDay}
</td>
)
);
}
});
// When press a day
handleDays = (actualRow, counterDay) => {
alert(actualRow + "-" + counterDay);
};
actualRowandcounterDay?