Revision d443c062-9413-4d4b-9358-9eae96e1c760 - Stack Overflow
How do I execute a JS object's class method from an HTML link?
I have the following JS:
function Tester(elem) {
this.elem = document.getElementById(elem);
}
Tester.prototype.show = function() {
this.elem.innerHTML = '<a href="javascript: this.test();">test</a>';
};
Tester.prototype.test = function() {
alert("a");
};
Here is the HTML:
<script type="text/javascript">
var test = new Tester("test");
test.show();
</script>
When I click on the link that gets rendered, it cannot identify the test() method. How would I get it so when a user clicks on the link, the test() method is executed?