I have two functions within a javascript class and I am trying to call one from inside the other, but it is not working. Why is that?
class Grid {
paintGrid() {
$("td").on("click", function() {
var color = $("#colorPicker").val();
$(this).css( "background-color", color);
})
}
makeGrid() {
$("#sizePicker").one("submit", function(e) {
let height = $("#inputHeight").val();
let width = $("#inputWeight").val();
var vertical;
for (var i = 1; i <= height; i++) {
var vertical = document.createElement("tr");
for (var j = 1; j <= width; j++) {
var horizontal = document.createElement("td");
vertical.append(horizontal);
$("#pixelCanvas").append(vertical);
}
};
e.preventDefault();
this.paintGrid();
})
}
}
let creation = new Grid();
creation.makeGrid();
The thing is: when I replace this.paintGrid()
for the function inside it, it works. So the error is on how I call it, I believe.