How to call a method from the javascript class from html?
I not find solution for to call class method from html generated code using javascript.
I write small example for better understand.
<head>
<script>
function MyClass() {
var self = this;
this.init = function() {
document.getElementById('list').innerHTML = this.mainTemplate();
};
this.mainTemplate = function () {
return '<button id="start" class="btn btn-danger btn-lg" onclick="onStart()" type="button"> value </button>';
};
this.onStart = function onStart() {
alert('bingo');
};
}
</script>
</head>
<body>
<div id ="list"> </div>
<script>
var a = new MyClass();
a.init();
//a.onStart();
</script>
</body>
I have tried everything that comes to mind, like ...
- onStart()
- self.onStart()
- this.onStart()
- MyClass.onStart()
- MyClass.prototype.onStart()
- a.onStart
- MyClass.onStart