I am generating checkboxes in a table (typescript) as follows:
generateTable(): void {
var table = document.getElementById("table1") as HTMLTableElement;
if (table.childElementCount == 2) {
for (var x = 0; x < 2; x++) {
var newRow = table.insertRow(x+1);
var newCell = newRow.insertCell(0);
newCell.innerHTML = "<input type='checkbox' onclick='toggleSelection()'>";
}
}
}
toggleSelection() {
console.log("Test");
}
Now, as soon as I click on either of the checkboxes, I receive the following console error:
Uncaught ReferenceError: toggleSelection is not defined at HTMLInputElement.onclick ((index):142:2)
I am not sure how to handle this error. It seems like the function "toggleSelection" is not properly defined. Help is very much appreciated!
Aucun commentaire:
Enregistrer un commentaire