I have an issue calling a method onChange from an element created by template literals. The element (checkbox) is created from the same class that includes a method that should be called by the onChange
event. I have the following two JS files. main.js and class1.js
main.js:
import {customClass} from './customClass.js';
let customClass= new CustomClass();
customClass.createCheckBox();
customClass.js:
export class CustomClass{
createCheckBox(){
return `<input type="checkbox" onchange='customClass.customMethod()'`>
}
customMethod(){
...//some functionality
}
}
When I select the checkbox I either get Uncaught TypeError: this.customMethod() is not a function
or I get undefined
. I tried to add this
into onchange='this.customMethod()
but I can’t get it working. Any help would be greatly appreciated.